title: Recursive sorting of linked list is my logic wrong?
body: <p>Whats wrong with it? its supposed to sort it in ascending order. it doesn't cause the program to crash but when I'm pretty sure theres something wrong because when I the linked list to other functions it gets stuck in an infinite loop.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  struct dataTag {
     int key;
  };
  
  struct nodeTag {
     struct dataTag data;
     struct nodeTag *pNext;
  };
  typedef struct dataTag dataStructType;
  typedef struct nodeTag nodeStructType;
  
  nodeStructType *SortList(nodeStructType *pFirst)
  {
      nodeStructType *swap,*ptr;
      if(pFirst == NULL)
          return NULL;
      else
      {
          swap = pFirst;
          ptr = pFirst -&gt; pNext;
          while(ptr != NULL)
          {
              if(ptr -&gt; data.key &lt; swap -&gt; data.key)
                  swap = ptr;
              ptr = ptr -&gt; pNext;
          }
          swap -&gt; pNext = SortList(pFirst -&gt; pNext);
          return swap;
      }
  }
  int main(void)
  {
     nodeStructType *pFirst;
     /* Lets say codes exists here that makes a link list etc just to make the code short*/
     pFirst = SortList(pFirst);
     /*Free List*/
     return 0;
  }
  </code></pre>