MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / buildTree

Function buildTree

CPP/Segment Tree/basic.cpp:4–17  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4void buildTree(vector<int> &nums, vector<int> &tree, int si, int ei, int idx)
5{
6 if (si == ei)
7 {
8 tree[idx] = nums[si];
9 return;
10 }
11
12 int mid = si + ((ei - si) / 2);
13
14 buildTree(nums, tree, si, mid, (2 * idx) + 1);
15 buildTree(nums, tree, mid + 1, ei, (2 * idx) + 2);
16 tree[idx] = tree[(2 * idx) + 1] + tree[(2 * idx) + 2];
17}
18
19void buildTree(vector<int> &nums, vector<int> &tree)
20{

Callers 1

mainFunction · 0.70

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected