MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Solution

Class Solution

TreeInOrderIterative.java:1–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2 public List<Integer> inorderTraversal(TreeNode root) {
3 Stack<TreeNode> stack = new Stack<TreeNode>();
4 List<Integer> inOrder = new ArrayList<Integer>();
5 if(root==null) return inOrder;
6 while(true)
7 {
8 if(root!=null)
9 {
10 stack.push(root);
11 root=root.left;
12 }
13 else
14 {
15 if(stack.isEmpty()) break;
16 root=stack.pop();
17 inOrder.add(root.val);
18 root=root.right;
19 }
20 }
21 return inOrder;
22
23 }
24}
25

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected