[eluser]dtrenz[/eluser]
Yes, there are a couple of assumptions required for my code to work. These should probably be addressed so that the function is more generic.
(1) The original array element order matters.
The elements need to be in order, so that no element should be listed until it's parent element has been added.
(2) The first element must be the top most parent
The elements need to be in order, so that the first element is the top-most parent.
There are obvious flaws to this logic, but it should be simple enough to fix these restrictions. I'll see if I can't fix these.
This sorting algorithm was just done on-the-fly and from scratch.