Preorder Traversal Iterative

Go down

Preorder Traversal Iterative

Post  skyboard on Mon Sep 05, 2011 12:33 am

public static preorder(TreeNode root){
Stack stack=new Stack();
stack.push(root);
while(true){
TreeNode temp=stack.pop();
if(temp.left){
stack.push(temp);
stack.push(temp.left);
}
else{
TreeNode right=temp.right;
if(right!=null)
stack.push(right);
}
}
}

skyboard

Posts : 31
Join date : 2011-09-03

View user profile

Back to top Go down

Back to top

- Similar topics

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