Non-recursive in-order traversal
Non-recursive in-order traversal is similar to pre-order traversal. The only difference is that it must first move to the left subtree of the node. After the left subtree is traversed, the node will be popped out of the stack for processing.
void inOrderNonRecursive(BinaryTreeNode root){
if(root == null){
return null;}
llStack S = new llStack();
while(true){
S.push(root);
root = root.getLeft();
}
if(stack.isEmpty()){
break;
}
root = (BinaryTreeNode)S.pop();
System.out.println(root.getData());
root = root.getRight();
}
return;
}