Need help with implementation of segment trees

Here the following code was given for implementaion of segtree:

struct segment_tree{
    segment_tree *left, *right;
    int from, to, value;
    segment_tree(int from, int to)
       :from(from), to(to), left(NULL), right(NULL), value(0){}
};

What does this line do ?

segment_tree(int from, int to)
       :from(from), to(to), left(NULL), right(NULL), value(0){}

Source: T-414-ÁFLV: A Competitive Programming Course | Bjarki Ágúst Guðmundsson

1

in case of point2 data structure you have to set the X , Y value explicitly

but in case of point you can set these value with just passing the argument

1 Like

I re-indented the code.

segment_tree(int from, int to) // constructor definition
	// here starts the initializer list
	:
		from(from),		// initializes `this->from` with `from`
		to(to),			// initializes `this->to` with `to`
		left(NULL),		// initializes `this->left` with `NULL`
		right(NULL),	// initializes `this->right` with `NULL`
		value(0)		// initializes `this->value` with `0`
{
	// body of the constructor
}

You may read more about it here.
Hope this helps. :slight_smile:

1 Like

Thanks for help @ajaymalik and @raisinten. :love_you_gesture:

1 Like