title: Bubble-sorting doubly linked list
body: <p>I have a problem with my bubble-sorting function for the doubly linked list.
  It is working when I'm sorting the nodes in the singly linked way (only with ->next), but I can't make it work with ->prev pointers.
  Here is the code I'm using:</p>
  
  <pre><code>void sort(int count)
  {
      struct data *tmp,*current,*nextone;
      int i,j;
      for(i=0;i&lt;count;i++)
      {
          current = first;
          for(j=0;j&lt;count-1-i;j++ )
          {
              if(current-&gt;number &gt; current-&gt;next-&gt;number)
              {
                  nextone = current-&gt;next;
                  current-&gt;next = nextone-&gt;next;
                  nextone-&gt;next = current;
                  if(current == first)
                  {
                      first = nextone;
                      current = nextone;
                  }
                  else
                  {
                      current = nextone;
                      tmp-&gt;next = nextone;
                  }
              }
              tmp = current;
              current = current-&gt;next;
          }
      }
  }
  </code></pre>
  
  <p>And this is the structure I'm using (with the global variables for the first and last element of the list):</p>
  
  <pre><code>struct data    
  {
      int id;
      char name[20];
      int number;
      struct data *next;
      struct data *prev;
  };
  
  struct data *first = NULL;
  struct data *last = NULL;
  </code></pre>