I am trying to figure out an algorithm to solve this problem:
I have a unsorted array, which contains nodes that will be used to build several non-binary trees. These nodes have a name, an id, and knowledge of who their parent is.
So currently these trees are built and just connect the root nodes to their descendants and display them in whatever order they were created.
So you would have the first tree with all of it's descendant followed by the next tree that happened to appear next in the original array connected with it's descendant and so on.
I need to alphabetically sort the root nodes so that the first tree is the node with the earliest name in the dictionary connected to it's descendants followed by the next one.
So I am essentially sorting trees themselves and not all nodes. The non-root nodes should NOT be sorted. So you can say if the node's parent is "null" then it is a root node.
NOTE: Programming in Javascript/Angular