I have a list of objects that look like this:
public class Test
{
public int Id;
public int Level; // The depth level of this node
public int ParentId; // The id of the parent node (null for level 1)
}
Two Important things to note are: 1) there is a maximum of 5 levels and 2) There is no root node. Aka, there can be multiple level 1 nodes
The current orientation of the list is each level concatenated on top of each other:
- Level 1 Items
- Level 2 Items
- Level 3 Items
- ... etc
I need the list in a Pre-order binary tree format. So for each level, the next item would be it's child recursing down.
Sorry if this is confusing.
I already had a somewhat working prototype but it requires a manual search and loop 5! times and it became a massive function.
I'm hoping there is a recursive way to accomplish this. Thanks in advance.