(TreeNode root, List<Integer> list)
| 20 | } |
| 21 | |
| 22 | public void inorder(TreeNode root, List<Integer> list){ |
| 23 | /* Inorder traversal is visiting : left subtree then root then right subtree */ |
| 24 | |
| 25 | /* if node is null, then return back to the caller function */ |
| 26 | if(root==null) |
| 27 | return; |
| 28 | /* Recurse for left subtree */ |
| 29 | inorder(root.left, list); |
| 30 | |
| 31 | /* Add the current node's value to the list */ |
| 32 | list.add(root.val); |
| 33 | |
| 34 | /* Recurse for right subtree */ |
| 35 | inorder(root.right, list); |
| 36 | } |
| 37 | } |