Skip to content

Instantly share code, notes, and snippets.

@rohith2506
Created March 4, 2015 05:50
Show Gist options
  • Save rohith2506/872fa6eddda59f30956e to your computer and use it in GitHub Desktop.
Save rohith2506/872fa6eddda59f30956e to your computer and use it in GitHub Desktop.
iterative pre order traversal
void preorder(root){
stk.push(root);
while(!stk.empty()){
cout << stk.top();
stk.pop();
if(root -> right) stk.push(root->right);
if(root -> left) stk.push(root -> left);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment