段树节点结构不清楚

时间:2015-12-20 14:42:18

标签: c++ data-structures structure segment-tree

我正在尝试构建一个分段树但是节点结构不清楚是否有人可以解释我找到的代码

struct node{ 
int count;
node *left, *right;

node(int count, node *left, node *right):
    count(count), left(left), right(right) {}//what this part is doing please explain and how it affects the complexity of the segment tree as compared to other initialization method

node* insert(int l, int r, int w);};

1 个答案:

答案 0 :(得分:1)

您指定的部分是具有初始化列表的构造函数。为了使其更加混乱,它使用与成员变量相同的参数名称。也许不那么令人困惑,可以编写完全相同的代码:

node(int cnt, node *lhs, node *rhs)
    : count(cnt), left(lhs), right(rhs)
{}

或者:

node(int cnt, node *lhs, node *rhs)
{
    count = cnt;
    left = lhs;
    right = rhs;
}
相关问题