title: Sorting a linked list in c++
body: <p>I'm getting mad with infinite loop, what do you think is suitable solution?</p>
  
  <pre><code>void sorting () {
    node * temphead = head;
    node * tempnode = NULL;
  
    for (int i=0; i&lt;count; i++) {
      for (int j=0; j&lt;count-i; j++) {
        if (temphead-&gt;data &gt; temphead-&gt;next-&gt;data) {
          tempnode = temphead;
          temphead = temphead-&gt;next;
          temphead-&gt;next = tempnode;
        }
  
        temphead=temphead-&gt;next;
        count++;
      }
    }
  }
  </code></pre>
  
  <p>I tried to increment count and use many conditions with while- before and after the for loop with no result</p>