Code for Inorder Traversal:
=>
public void printInOrder(){
if(root == null){
return;
}
Stack stack = new Stack(numNodes);
Node node = root;
while(node != null){
stack.push(node);
node = node.left;
}
while(! stack.isEmpty()){
node = stack.pop();
System.out.println(node.data);
if(node.right != null){
stack.push(node);
node = node.left;
}
}
}
No comments:
Post a Comment