• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Recursive Methods

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone,
I wrote this dummy tree class which is associated to itself, and i populate it using a recursive method. The recursive method, getMyChildren, is used to add child objects to parent object, and then grandchildren to children, and so on.
In my method, after the recursion, I test the collection of children and they're always empty, even though they're not.
Does anyone know why this happens? I would appreciate any thoughts.

Here is my code:

 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm having an extremely hard time following the logic here, or why a method called "getMyChildren" would be the way to build a a tree in the first place. But in any case, there's only one place in the whole program where you call children.add():



So if there are already some children, add a new child. But of course, since we start out with no children, that's never going to change.
 
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic