Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void inOrder(struct Node *root)
- {
- stack<Node *> s;
- Node *curr = root;
- while (curr != NULL || s.empty() == false)
- {
- /* Reach the left most Node of the
- curr Node */
- while (curr != NULL)
- {
- /* place pointer to a tree node on
- the stack before traversing
- the node's left subtree */
- s.push(curr);
- curr = curr->left;
- }
- /* Current must be NULL at this point */
- curr = s.top();
- s.pop();
- cout << curr->data << " ";
- /* we have visited the node and its
- left subtree. Now, it's right
- subtree's turn */
- curr = curr->right;
- } /* end of while */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement