|
|
|
|
|
by taeric
4206 days ago
|
|
You only have to remember the link you just followed. Basically, make a boolean "followedThread" and initialize to false. Then, go to the root and follow this algorithm if (!followedThread && left != null)
set followedThread <- curNode.left.isThread
set curNode <- curNode.left.node
else
set followedThread <- curNode.right.isThread
set curNode <- curNode.right.node
Only node you really have to special case is the root node, and you can do that by making its right.node == null. Then you just do this while curNode != null.That make sense? (Also... very possible that I made a mistake here...) |
|