Last active
August 29, 2015 14:09
-
-
Save kartikkukreja/5a8d9a7d84682aab7228 to your computer and use it in GitHub Desktop.
Building a segment tree
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void buildTree(T arr[], int stIndex, int lo, int hi) { | |
if (lo == hi) { | |
nodes[stIndex].assignLeaf(arr[lo]); | |
return; | |
} | |
int left = 2 * stIndex, right = left + 1, mid = (lo + hi) / 2; | |
buildTree(arr, left, lo, mid); | |
buildTree(arr, right, mid + 1, hi); | |
nodes[stIndex].merge(nodes[left], nodes[right]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment