aspose file tools*
The moose likes Beginning Java and the fly likes Recursive code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Recursive code" Watch "Recursive code" New topic
Author

Recursive code

Shelly Biswal
Greenhorn

Joined: Sep 07, 2007
Posts: 17
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

Joined: Jan 23, 2008
Posts: 410

What is the relation between parent and child?


Pawan Chopra
SCJP - DuMmIeS mInD
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38357
    
  23
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

Joined: Sep 07, 2007
Posts: 17
Thanks Campbell, your post helped me
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38357
    
  23
You're welcome
 
wood burning stoves
 
subject: Recursive code