C++ struct constructor

node t[100];

will try to initialise the array by calling a default constructor for node. You could either provide a default constructor

node()
{
    val = 0;
    id = 0;
}

or, rather verbosely, initialise all 100 elements explicitly

node t[100] = {{0,0}, {2,5}, ...}; // repeat for 100 elements

or, since you’re using C++, use std::vector instead, appending to it (using push_back) at runtime

std::vector<node> t;

Leave a Comment