Print all paths from root to leaf in a Binary tree
Here is the code I wrote to print all paths of a Binary tree from root to leaf: public static void printRootToLeaf(Node1 root, List<Integer> list) { if(root == null) { return; } list.add(root.data); if(root.left == null && root.right == null) { System.out.println(list); return; } printRootToLeaf(root.left, list); printRootToLeaf(root.right, list); } I am calling this method in main like this: public static void main(String[] args) { Node1 root = new Node1(1); Node1 two = new Node1(2); Node1 three = new Node1(3); Node1 four = new Node1(4); Node1 five = new Node1(5); Node1 six = new Node1(6);