title: Merge-sorting a linked list
body: <p>I'm required to sort a Linked list using merge sort. I've put together this code, but I'm running into a weird error.</p>
  
  <p>My linked list is populated by random numbers. However, after sorting, it only displays numbers that are larger than the first element of the linked list, in sorted order.</p>
  
  <p>Here is some of my code:</p>
  
  <pre><code>node* MergeSort(node *my_node)
  {
      node *secondNode;
  
      if (my_node == NULL)
          return NULL;
      else if (my_node-&gt;next == NULL)
          return my_node;
      else
      {
          secondNode = Split(my_node);
          return Merge(MergeSort(my_node),MergeSort(secondNode));
      }
  }
  
  node* Merge(node* firstNode, node* secondNode)
  {
      if (firstNode == NULL) return secondNode;
      else if (secondNode == NULL) return firstNode;
      else if (firstNode-&gt;number &lt;= secondNode-&gt;number) //if I reverse the sign to &gt;=, the behavior reverses
      {
          firstNode-&gt;next = Merge(firstNode-&gt;next, secondNode);
          return firstNode;
      }
      else 
      {
          secondNode-&gt;next = Merge(firstNode, secondNode-&gt;next);
          return secondNode;
      }
  }
  
  node* Split(node* my_node)
  {
      node* secondNode;
  
      if (my_node == NULL) return NULL;
      else if (my_node-&gt;next == NULL) return NULL;
      else {
          secondNode = my_node-&gt;next;
          my_node-&gt;next = secondNode-&gt;next;
          secondNode-&gt;next = Split(secondNode-&gt;next);
          return secondNode;
      }
  }
  </code></pre>