@don : right.... didn't check the flow of code correctly ....

On Mon, Jan 30, 2012 at 9:53 PM, Don <dondod...@gmail.com> wrote:

> Right idea. But you only need to remove the last item once, right at
> the end of the function.
> Don
>
> On Jan 30, 1:01 am, atul anand <atul.87fri...@gmail.com> wrote:
> > @Mihir : actually you are using linked list....so you are keep on adding
> > the nodes but not removing it..hence...you are getting wrong output..
> >
> > i guess this should be done to fix the code.....
> >
> > 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);
> >
> > *      removeLastNodefromLinkedList();*
> >       paths(node.right, list);
> >
> >    *   removeLastNodefromLinkedList();*
> >
> >    }
> >
> > r*emoveLastNodefromLinkedList();*
> >
> > }
> >
> > public static void print(LinkedList<Integer> list) {
> >    System.out.println("Contents of list: " + list);
> >
> > }
> >
> > On Mon, Jan 30, 2012 at 11:41 AM, Mihir Kulkarni <mihirk...@gmail.com
> >wrote:
> >
> >
> >
> > > I only intend to print the root to leaf paths. The correct output
> should
> > > be:
> > > 721
> > > 725
> > > It works fine when I use array instead of LinkedList.
> >
> > > cheers,
> > > Mihir Kulkarni
> > > Graduate Student
> > > University of California, Irvine
> > >http://goo.gl/CvRcG
> >
> > > On Sun, Jan 29, 2012 at 10:06 PM, Rujin Cao <drizzle...@gmail.com>
> wrote:
> >
> > >> Is the correct output   7 2 1 5 ?
> >
> > >> Did you intend to print the leaf node ?
> >
> > >> --
> > >> 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.- Hide quoted text -
> >
> > - Show quoted text -
>
> --
> 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.

Reply via email to