Iterative way of in order traversal

View previous topic View next topic Go down

Iterative way of in order traversal

Post  Admin on 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

View user profile http://codefornongeek.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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