java - How to traverse up "nodes"? -
I can not find the right search term (as I'm sure this question has already been asked), so I Will ask again
How do I write code to go to the "last" of the node until it is no longer? Note: I do not have permission to use supportive methods (so I do not think I can use recursive methods).
Basically I want to print the "Previous" of a node (which points to the previous node). Example
pseudocode):
node.prev node.prev.prev node.prev.prev.prev Edit: < / Strong> I'm not really working from nodes, it's more accurate, so I have actors, which is a "label", which points to the previous actor. I am trying to write a loop for something like this: A = g.label (actor); B = g.label (a); C = g.label (b); When I write this code:
while (g.label (a)! = Null) {a = g.label (a) }} I get stuck on the actor long ago.
If I understand the question correctly, do you want to cross the bottom tree?
There is no good way to do this if every node only presents the child node only if each node has a child and a parent (or in this case only refers to the parents), then this Should be very easy.
node currentNode = new MyNode (); While (currentNode.parent! = Tap) {currentNode = currentNode.parent; } // currentNode should now be the highest node in the tree
Comments
Post a Comment