Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Iterative way of in order traversal

Go down

Iterative way of in order traversal Empty Iterative way of in order traversal

Post  Admin Wed Sep 07, 2011 7:11 pm

public void inOrderTraversal(TreeNode root){
Stack<TreeNode> stack=new Stack<TreeNode>();
pushLeft(root,s);

while(!s.isEmpty()){
TreeNode temp=stack.pop();
System.out.println(temp);
pushLeft(temp.right,s);
}
}

public void pushLeft(TreeNode node, Stack s){
while(node!=null){
s.push(node);
node=node.left;
}
}

Admin
Admin

Posts : 131
Join date : 2011-08-16

https://codefornongeek.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum