Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. void inOrder(struct Node *root)
  2. {
  3. stack<Node *> s;
  4. Node *curr = root;
  5.  
  6. while (curr != NULL || s.empty() == false)
  7. {
  8. /* Reach the left most Node of the
  9. curr Node */
  10. while (curr != NULL)
  11. {
  12. /* place pointer to a tree node on
  13. the stack before traversing
  14. the node's left subtree */
  15. s.push(curr);
  16. curr = curr->left;
  17. }
  18.  
  19. /* Current must be NULL at this point */
  20. curr = s.top();
  21. s.pop();
  22.  
  23. cout << curr->data << " ";
  24.  
  25. /* we have visited the node and its
  26. left subtree. Now, it's right
  27. subtree's turn */
  28. curr = curr->right;
  29.  
  30. } /* end of while */
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement