MCPcopy Create free account
hub / github.com/acm-clan/algorithm-stone / buildTree

Method buildTree

templates/segment-tree.cpp:26–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24 TreeNode * root;
25
26 TreeNode * buildTree(vector<int>& nums, int l, int r)
27 {
28 if(l == r){
29 // 叶子节点
30 return new TreeNode(l, r, nums[l]);
31 }
32
33 // 后序构造
34 auto left = buildTree(nums, l, (l+r)/2);
35 auto right = buildTree(nums, (l+r)/2+1, r);
36
37 // 非叶子节点
38 return new TreeNode(l, r, left->v+right->v, left, right);
39 }
40
41 void dumpInternal(TreeNode * n, int d){
42 if(!n)return;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected