• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Recursive code

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have the following

1) a list of strings. These strings are related to each other as parent and children.
For e.g, if my list contains a,b,c,d, then a is parent of c and b, c is parent of d.
each child can have only one parent.

I need to write logic to pass this list in an iterator and keep finding the parents till the root(in e.g. it is a) and in each iteration i need to check for an attribute of the parent(by passing parent in some xyz method).

Please let me know how i could implement this logic.

Hoping for a response soon.

Regards,
Shelly
 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the relation between parent and child?
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is difficult to understand for your description to know exactly what you need, I am afraid. It sounds as though you are trying to create a parse tree from different tokens in your String.

Get a pencil and paper and write out what you require: structure before and structure after. It appears each token acts as a binary operator in prefix notation. Have a look at my post about parse trees and arities of operators only that was in postfix, so it is slightly different.
Then write down what you plan to implement (not what you would like us to implement ) and let us see what we think of it.

But I still think that understanding the basic concept is the most important part of the process.
 
Shelly Biswal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Campbell, your post helped me
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
reply
    Bookmark Topic Watch Topic
  • New Topic