Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static <E> void nonRecursive(BTNode<E> root)
- {
- Stack<BTNode<E>> S = new Stack<BTNode<E>>();
- while (1 != 0)
- {
- if (root != null)
- {
- S.push(root);
- root = root.getLeft();
- }
- else
- {
- if (S.isEmpty())
- {
- break;
- }
- else if (S.peek().getRight() == null)
- {
- root = S.pop();
- System.out.print(root.getData() + " ");
- if (root == S.peek().getRight())
- {
- System.out.print(S.peek().getData() + " ");
- S.pop();
- }
- }
- if (!S.isEmpty())
- {
- root = S.peek().getRight();
- }
- else
- root = null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement