MCPcopy Index your code
hub / github.com/Tiwarishashwat/InterviewCodes / inorderTraversal

Method inorderTraversal

TreeInOrderIterative.java:2–23  ·  view source on GitHub ↗
(TreeNode root)

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 4

pushMethod · 0.80
popMethod · 0.80
isEmptyMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected