Advertisement
Masfiq_ds_algo

DS: Tree: trsverse:: inorder, preorder, post order

Mar 25th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. /*
  2. *    Masfiq
  3. *    25 march, 2017
  4. */
  5. //Node is defined as  
  6.  
  7. struct node
  8. {
  9.     int data;
  10.     node* left;
  11.     node* right;
  12. };
  13.  
  14. */
  15.  
  16. void inOrder(node *root) {
  17.     if(root->left != 0)
  18.         inOrder(root->left);
  19.     printf("%d ", root->data);
  20.     if(root->right != 0)
  21.         inOrder(root->right);
  22. }
  23. void preOrder(node *root) {
  24.     printf("%d ", root->data);
  25.     if(root->left != 0)
  26.         preOrder(root->left);
  27.     if(root->right != 0)
  28.         preOrder(root->right);
  29. }
  30. void postOrder(node *root) {
  31.     if(root->left != 0)
  32.         postOrder(root->left);
  33.     if(root->right != 0)
  34.         postOrder(root->right);
  35.     printf("%d ", root->data);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement