This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem organizing text in file  RSS feed

 
nick angel
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone. This is my first post. I have run into a bit of a problem. However I am not looking for an answer just a nudge in the right direction.

On with the problem. I have a text file which contains information presented using the following formats:

topMenu1
topMenu2
topMenu3...

subMenu1
subMenu2
subMenu3... (in this case subMenu1 is a sub menu of topMenu1)

subMenu11 (in this case, subMenu11 is a sub menu of subMenu1)
subMenu12
subMenu21
subMenu31
subMenu32...

Ultimately we need to reorder the text file to present the data as a tree:
e.g.:
topMenu1
subMenu1
subMenu11
subMenu12 etc..

I have tried manipulating the strings as they are read using a bufferedreader, but either I don't retrieve the proper data or I get many duplicates of the same data. Any help would be greatly appreciated.

Thank you
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Natural ordering of the input lines can be used to solve the problem provided if topMenuX could be placed before subMenuX. If so, it is just mere reading the input lines, sort them and write to the output file.

Sorting topMenuX before subMenuX can be done by writing your own comparator which would do this. The complete example is given below.



[ December 14, 2005: Message edited by: Santhosh Kumar ]
[ December 14, 2005: Message edited by: Santhosh Kumar ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!