View Single Post
  #2 (permalink)  
Old 04-29-2007, 11:39 AM
levent levent is offline
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
As far as i understand, the second column in your input file is the parent of that node.

If so, it is simple.

First of all, you will get two integers instead of one for each line (use str=st.nextToken(); a[i]=Integer.parseInt(str); two times to get two integers).

You will make the first line as root node and for other nodes, you will find parent of that node. So for "4 6" input, you will look for the parent 6 starting from root node. Normally that will require you to traverse the tree but as far as i see you keep previous nodes inside an array. So you will only need to search that array. Once you find it, you will add new node under that parent using "insert".

Try to implement this algorithm. And if you need more help, let us know.
Reply With Quote