How to access individual elements of a vector element using pointer?

134 Views Asked by At

I want to do a pre-order traversal of an n-array tree. My tree node struct contains a vector pointer member. So, how can I iteratively call the members.

I want to do something like:

for(i in node->children){
    cout<<i;
}

The Node class is defined as follows:

class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
1

There are 1 best solutions below

0
On
for (Node *child: node->children) {
    // do something with child
}