Sumanto Dinar
Sumanto Dinar

Reputation: 97

What does node(){} mean?

struct node{
   int key, prior, cnt, val;
   node *l, *r;
   node(){}
   node(int nkey) : key(nkey), prior(rand()), cnt(1), l(0), r(0), val(1){}
};

What does node(){} do ? please explain it, thank you.

Upvotes: 0

Views: 108

Answers (2)

Mohit Jain
Mohit Jain

Reputation: 30489

What does node(){} do ? please explain it

node(){} looks like treap node. Code node(){} is the syntax for defining the default constructor.

Without default constructor, you can't use node in stl containers like std::array, std::vector etc without extra code so you need the definition for default. In coding competitions, people tend to write the minimal code and use the existing functionality as much as possible sometimes even at the cost of leaking scope etc.

Upvotes: 0

Paul Evans
Paul Evans

Reputation: 27577

It defines the the default constructor node() as an empty function {}.

Upvotes: 1

Related Questions