use array, not clear on JAVA front though, but logic is fine, pass the vector and index instead Best Regards Ashish Goel "Think positive and find fuel in failure" +919985813081 +919966006652
On Mon, Jan 30, 2012 at 11:04 AM, Mihir Kulkarni <mihirk...@gmail.com>wrote: > Hello, > This method below is not giving correct paths. Can someone please tell me > the mistake. > > public static void paths(Node node, LinkedList<Integer> list) { > if(node == null) return; > list.add(node.data); > > if(node.left == null && node.right == null) { > print(list); > } > else { > paths(node.left, list); > paths(node.right, list); > } > > } > > public static void print(LinkedList<Integer> list) { > System.out.println("Contents of list: " + list); > } > > e.g: > 7 > / > 2 > / \ > 1 5 > > It prints: > 7 2 1 > 7 2 1 5 > cheers, > Mihir Kulkarni > Graduate Student > University of California, Irvine > http://goo.gl/CvRcG > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.