• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

representing data in tree structure way

 
R .sourav nayak
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i have to write a java class to represent the data in tree structure. In database the datas are being declared in tree structure way.

could some one provide me java class. which will help me retrive those datas in structural way.

thanks in advance
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We always ask how far you've gotten and where you are stuck. Do you know how you want to make a tree in memory? Look in the JavaDoc for TreeNode and see if that gives you some ideas. How is the tree stored in the database? That will make a lot of difference when it comes time to load it.
 
R .sourav nayak
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
thanks for the replay.on the database data's are stored in toplevel,sublevel and the leafnodes related to sublevel. In my java code i am able iterate through the node and leaf nodes. but i am having a problem string that in a list and bringing that to my jps page in a tree structure way. below is my cod e.


could you tell me how do i temporarily store it in a list after each iteration and call that on my jsp altogeter.

thanks in advance
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're missing a bit to add each new child to its parent. I'm going to use generic Nodes because I'm not sure I understand your data fully. Let's say a Node has an Object that we're interested in and a collection of children.

Now your JSP (or some other code) can walk the object graph from Root on down. Does that make sense?

BTW: You can write the for loop one line shorter:

[ November 15, 2007: Message edited by: Stan James ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic