Forum Moderators: open
My basic need is to be able to
1. Define a tree
2. Define a parent node
3. Define children of that parent
4. Create children of a child node (either by making it a parent, or however it is done).
Consider all the nodes to just be strings...nothing fancy...and no need for anything design time..strictly data in memory
Can anyone help me with this?
Consider the following example (maybe it will help?)
Parent / Child
--------------
A / B
A / C
A / D
B / E
B / F
C / F
C / G
Thanks in advance for any help
-Mike
Search for 'linked list'. I think this is what you are looking for.
Sidenote: Your example structure has an error. Node F violates a valid tree structure, as it has two parents, B and C .
I would have something along the lines of this:
A table defined as:
ID, ParentID, Data
Set ParentID = ID = 1 for the root node.
To create a child, insert a new row, setting the ParentID
to the existing ID of the node you are on.
Then you can recurse through the table from ID = 1 to get all of your values.
Emsaw, the linked list information looks very promising, and I'm trying to re-familiarize myself with OOP in order to figure out how to make use of this for my project (I'm a jack of all trades...NOT a hardcore programmer...so this stuff doesnt' come easy to me)
Aspdaddy, unfortunatley for me my research has pointed to the fact that c# does not in fact have a built in tree library...the only built in object is ArrayList, or you have to build your own Linked List class (tantamount to building your own tree object)
The reason I keep asking so many questions about trees and the sort is that I'm working on a routing project. The basic jist of the project is that there are locations, and links between locations. By selecting a start point (Point A) and an end point (Point B) the logic of the code should be able to trace the route between the two (if it exists)
My database table that stores the data is exactly similar to the example in my first post with Parent/Child combinations.
I have created working code that accomplishes my goal using a DataSet formed from the data example and recusively parsing through it. The reason for my interest in tree building is to optimize the format of the data (and in the proecess optimize the code) so that additional modules of the project are easier to implement.
Again, all your help is greatly appreciated
-Mike
Your table looks correct, you just need to make both columns a composite primary key unless you need to know about direction, then you need a third column of type bit and make all 3 the key.
The search algorithm is the hard/interesting part. I dont know if the data structures are the right approach to optimisation. Have you ever looked at Dash Xpress or ILog stuff? Dash can model & solve this problem in a fraction of a second . If its a commercial project I would definetley take a look, you might get some more ideas anyway, thery are good toys to play with :)