Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

data structures - Build Nested Menu from Flat List (Using Parent, Child, or Level Information)

Here is the list I am pulling from my database:

Here is the list I am pulling from my database

As you can see by the Level information, it is ordered correctly, and I have read this ordered-list into an array. Now, I can iterate over the array to decide where to insert each item into my tree.

I am seeking help with algorithm logic to create the tree. Particularly, how to keep track of parents so that I may "go back up a level" in the tree, when I need to. For example, after Level 2 siblings are entered, to add a node on 'Level 1'.

I enter items into my menu based on what level they are.

  • If current item level is greater than previous item level, it is a child.
  • If current item level is equal to previous item level, it is a sibling.
  • If current item level is lower than previous item level, I need to go back up a level and insert a node.

I only have an AddNode function implemented! How do I keep track of parents and build this tree with the tools I have on hand? That is, using just an AddNode function. These nodes are added to an XML document which is published to the web.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...