Skip to content

Instantly share code, notes, and snippets.

@wohhie
Created July 9, 2021 01:38
Show Gist options
  • Select an option

  • Save wohhie/08c392f24a39cdf5227fe1402666faa6 to your computer and use it in GitHub Desktop.

Select an option

Save wohhie/08c392f24a39cdf5227fe1402666faa6 to your computer and use it in GitHub Desktop.
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