Hi,
I have a list of object I wish to sort in C#.Net 3.5, the object is as follows
id | name | parent_id
1 | Superman | NULL
2 | Batman | 3
3 | Watchman | 1
4 | Wolverine | 2
I know some of you might find this easy, but I need to sort the list based on the parent_id, which is pointing to its own index(id) in the same table.
So can someone give me a good algorithm to sort this list without looping over and over again? I cannot really phrase it that well, therefore I can't seem to google the right results I wanted.
A collection of IEnumerable or DataTable solution would be great.
Thanks in advance.
EDIT:----------------NEW Example
id | name | parent_id
1 | TOP CHILD | NULL
2 | Child C | 3
3 | Child B | 4
4 | Child A | 1
----> The Output I want is
id | name | parent_id
1 | TOP CHILD | NULL
4 | Child A | 1
3 | Child B | 4
2 | Child C | 3
----> If I use OrderBy or Sort, the result I get is
id | name | parent_id
1 | TOP CHILD | NULL
4 | Child A | 1
2 | Child C | 3
3 | Child B | 4
--> Non of the solutions is what I really wanted, Sorry again for not being clear
Hope this example is clearer