MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / travel

Method travel

Programs/BinaryTreeInorder.java:15–25  ·  view source on GitHub ↗
(Node root, ArrayList<Integer> ans)

Source from the content-addressed store, hash-verified

13 }
14
15 public static void travel(Node root, ArrayList<Integer> ans)
16 {
17 if(root==null) return;
18
19 //if there is node on left, go there
20 if(root.left!=null)travel(root.left,ans);
21 //add the element to list
22 ans.add(root.data);
23 //if there is node on right, go there
24 if(root.right!=null)travel(root.right,ans);
25 }
26 }
27 //Time Complexity : o(n)
28 //Space Complexity : o(n)

Callers 1

inOrderMethod · 0.95

Calls 1

addMethod · 0.65

Tested by

no test coverage detected