Created
July 9, 2021 01:38
-
-
Save wohhie/08c392f24a39cdf5227fe1402666faa6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void iterativeInOrder(Node node){ | |
| // we are going to the left most item | |
| if (node == null) return; | |
| // create an empty stack and push root to it. | |
| Stack<Node> stack = new Stack<>(); | |
| while (node != null || !stack.isEmpty()){ | |
| // 1. inOrder(left_child) // put the data into stack | |
| // 2. Print(node.data) | |
| // 3. inOrder(right_child) | |
| if (node != null){ | |
| stack.push(node); | |
| node = node.left; | |
| }else{ | |
| node = stack.pop(); | |
| System.out.print(node.data + " "); | |
| node = node.right; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment