Skip to content

Commit

Permalink
Merge pull request #1 from Bhupesh-V/master
Browse files Browse the repository at this point in the history
Preorder Traversal

Added Pre-Order traversal function for the Binary Search Tree.
  • Loading branch information
Animesh-Ghosh authored Sep 20, 2018
2 parents ea5c73e + b01b1bd commit b2c134c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ void Traverse (NODE *root) {
cout<<cur->data<<" ";
if (cur->right != NULL) Traverse (cur->right);
}

void preorder(NODE*root){
//NODE*cur=root;
if(root==NULL) return;
cout<<root->data<<" ";
preorder(root->left);
preorder(root->right);
}
// main
int main () {
NODE *root = NULL;
Expand All @@ -59,5 +65,7 @@ int main () {
*/
cout<<"Tree in INORDER traversal: "<<endl;
Traverse (root);
cout<<"\nTree in PRE-ORDER traversal: "<<endl;
preorder (root);
return 0;
}

0 comments on commit b2c134c

Please # to comment.