title: Sorting root nodes for trees algorithm
body: <p><strong><em>I am trying to figure out an algorithm to solve this problem:</em></strong></p>
  
  <p>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.</p>
  
  <p>So currently these trees are built and just connect the root nodes to their descendants and display them in whatever order they were created.</p>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <p>So I am essentially sorting trees themselves and not all nodes. The non-root nodes should <strong>NOT</strong> be sorted. So you can say if the node's parent is "null" then it is a root node.</p>
  
  <p>NOTE: Programming in Javascript/Angular</p>