// non-recursive algorithms for first-order traversal
private void preordertraverse (bintreenode RT, Skip List) {
If (RT = NULL) return;
bintreenode P = RT;
stack S = new stackslinked ();
while (P! = NULL) {
while (P! = NULL) {// left to the end
list. insertlast (p); // access root
If (P. hasrchild () s. push (P. getrchild (); // The right child root node is added to the stack
P = P. getlchild ();
}< br> If (! S. isempty () P = (bintreenode) S. Pop (); // The right subtree goes back to stack to traverse the right subtree
}< BR >}
// Non-recursive algorithm for sequential Traversal
Private void inordertraverse (bintreenode RT, sorted list ){
If (RT = NULL) return;
Bintreenode P = RT;
Stack S = new stackslinked ();
While (P! = NULL |! S. isempty ()){
While (P! = NULL) {// keep walking to the left
S. Push (p); // Add the root node to the stack
P = P. getlchild ();
}
If (! S. isempty ()){
P = (bintreenode) S. Pop (); // retrieve the top root node of the stack to access
List. insertlast (P );
P = P. getrchild (); // redirect to the right subtree of the root for Traversal
} // If
} // Out while
}
// Non-Recursive Algorithms for post-order traversal
Private void postordertraverse (bintreenode RT, writable list ){
If (RT = NULL) return;
Bintreenode P = RT;
Stack S = new stackslinked ();
While (P! = NULL |! S. isempty ()){
While (P! = NULL) {// go left and right
S. Push (p); // Add the root node to the stack
If (P. haslchild () P = P. getlchild ();
Else P = P. getrchild ();
}
If (! S. isempty ()){
P = (bintreenode) S. Pop (); // retrieve the top root node of the stack to access
List. insertlast (P );
}
// When the conditions are met, it indicates that the right subtree of the root node on the top of the stack has been accessed and the right subtree should be accessed from the egress
While (! S. isempty () & (bintreenode) S. Peek (). getrchild () = P ){
P = (bintreenode) S. Pop ();
List. insertlast (P );
}
// Switch to the right subtree of the top root node of the stack to continue post-sequential Traversal
If (! S. isempty () P = (bintreenode) S. Peek (). getrchild ();
Else P = NULL;
}
}
// uses a queue to traverse Binary Trees.
private void levelordertraverse (bintreenode RT, sorted list) {
If (RT = NULL) return;
queue q = new queuearray ();
q. enqueue (RT); // enter the root node
while (! Q. isempty () {
bintreenode P = (bintreenode) Q. dequeue (); // retrieve the first node P of the team and access it
list. insertlast (p);
If (P. haslchild () Q. enqueue (P. getlchild (); // The left and right children of P are queued in sequence
If (P. hasrchild () Q. enqueue (P. getrchild ();
}< BR >}