Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Recursive code

 
Shelly Biswal
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • 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
 
pawan chopra
Ranch Hand
Posts: 417
jQuery Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the relation between parent and child?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks Campbell, your post helped me
 
Campbell Ritchie
Sheriff
Pie
Posts: 50196
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic