-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
return wrong results when calling get() function after removing operation #5
Comments
This happen because the id of every node added after node1 depends on node1 presence t = tree('root'); %% root is id = 1 t.get(node2) // rightly result what is now in id=3. which is 'Child of node 1' and not 'Node 2' anymore. The tree structure is implemented as a list of nodes and parents ( though, i think it would've been better to implement it as a list of node / parent / child vector. While harder to manage, it would've been much faster to delete parents, create the depth and breadth iterators that are used quite a lot and such ) |
t = tree('root');
[ t node1 ] = t.addnode(1, 'Node 1'); %% attach to root
% node1 now contains the index of the first node.
[ t node2 ] = t.addnode(1, 'Node 2'); %% attach to root
[ t node11 ] = t.addnode(node1, 'Child of node 1'); %% attach to first node
disp(t.tostring)
t=t.removenode(node1);
disp(t.tostring);
t.get(1)
t.get(node2) // wrong result return!
I expected the result of get(node2) is 'Node 2', but get the 'Child of node 1'! why???
where is wrong?
The text was updated successfully, but these errors were encountered: