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