From the description that you indicated in the tree structure that you are implementing, it is best to create a new data structure that mimics your tree. Especially if you are already tracking pointers between nodes.
, node node . node, , , node node.
:
N1->N2->(n3,n4,n5,n6,n7,n8) N2 : N1->(N2_1, N2_2) N2_1->(n3,n4,n5) N2_2->(n6,n7,n8)
(, , ...)
, , , log n. , .
:
, N1->N2->(n3,n4,n5,n6,n7,n8). N1 , N1 node: N1->(N2,N9)->(n3,n4,n5,n6,n7,n8)
node ( ):
class Node {
vector<Node *> children;
Node * parent;
};
, . node , children node. .