I have a DataTable that has the following structure:
Root | Level 1 | Level 2 | Level 3 | Tree L | Tree R
Food 1 18
Fruit 2 11
Red 3 6
Cherry 4 5
Yellow 7 10
Banana 8 9
Meat 12 17
Beef 13 14
Pork 15 16
Using C#, I need to traverse this structure and calculate the correct Tree L and Tree R values for each node. This is just an example, the real structure has several hundred nodes that go out to at least Level 7, but possibly more.
Can anyone suggest how I might approach the code for calculating the left and right values?
So, you want to keep track of the visit order of the tree, but you have the order split into
LandR. Those correspond to the "entrance" and "exit" of theVisitfunction for theNodestructure. Assuming aNodeclass with aNode.Visit()method, you could:When you finish, all you have to do is do is look at the
VisitOrdervalues. They're stored in theListin increasing order, where the index corresponds to it's position in the visit sequence. Each item in theList, then, is aTupledescribing which value it corresponds to and whichNodeit visited.Edit:
To get the final output format, you could then do something like: