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

Preorder Traversal Iterative

Go down

Preorder Traversal Iterative Empty Preorder Traversal Iterative

Post  skyboard 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

Back to top Go down

Back to top


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