L
Lovingu.McDull
I am currently using Tree::Simple module.
I originally have a tree x. My task is to insert a node G into x, so
that the B node under A go under G.
My solution is: I create G first, then G->addChild(B). then disconnect
B from A, finally A->addChild(G).
x:
A
/ \
B E...
/\ |
C D F...
y:
A
/ \
G E...
| |
B F...
/\
C D
But it seems the disconnection can't be achieved by using
removeChild(), according to the specification,
"When a child is removed, it results in the shifting up of all
children after it, and the removed child is returned."
That is, if i delete B from x, the tree will look like this. It is
difficult for me to A->addChild(G) to this intermediate tree.
A
/ \ \
C D E...
|
F...
Any suggestions? //P.S. I prefer a solution in which the nodes are
relocated rather than being removed and regenerated.
I originally have a tree x. My task is to insert a node G into x, so
that the B node under A go under G.
My solution is: I create G first, then G->addChild(B). then disconnect
B from A, finally A->addChild(G).
x:
A
/ \
B E...
/\ |
C D F...
y:
A
/ \
G E...
| |
B F...
/\
C D
But it seems the disconnection can't be achieved by using
removeChild(), according to the specification,
"When a child is removed, it results in the shifting up of all
children after it, and the removed child is returned."
That is, if i delete B from x, the tree will look like this. It is
difficult for me to A->addChild(G) to this intermediate tree.
A
/ \ \
C D E...
|
F...
Any suggestions? //P.S. I prefer a solution in which the nodes are
relocated rather than being removed and regenerated.