title: Bubble sort with linked list C
body: <p>My sort algorithm does not seem to work in some cases. I'm acting on a doubly linked list (with pointer on the previous and next ones). I submit the definition of my structure and the essential. I find myself with a infinite loop, with  specific cases like this one. I use <code>strcmp()</code> function, to sort.</p>
  
  <pre><code>#include "string.h"
  #include "stdlib.h"
  #include "stdio.h"
  
  typedef struct s_file {
      char    *name;
      struct s_file     *next;
      struct s_file     *previous;
  } t_file;
  
  void swap_files(t_file *file, t_file *next)
  {
      t_file *previous;
  
      previous = file-&gt;previous;
      if (previous)
          previous-&gt;next = next;
      file-&gt;next = next-&gt;next;
      file-&gt;previous = next;
      if (next-&gt;next)
          next-&gt;next-&gt;previous = file;
      next-&gt;next = file;
      next-&gt;previous = previous;
  }
  
  static t_file *sort_files(t_file *files)
  {
      t_file *file;
      t_file *next;
  
      file = files;
      while ((next = file-&gt;next))
      {
          if (strcmp(file-&gt;name, next-&gt;name) &gt; 0)
          {
              swap_files(file, next);
              if (!next-&gt;previous)
                  files = next;
              file = files;
              continue;
          }
          file = file-&gt;next;
      }
      return (files);
  }
  
  void debug(t_file *files)
  {
      while (files)
      {
          printf("=&gt; %s\n", files-&gt;name);
          files = files-&gt;next;
      }
  }
  
  int main(void)
  {
      t_file second;
      t_file first;
      t_file third;
  
      first.name = "Poire";
      first.previous = NULL;
      first.next = &amp;second;
  
      second.name = "Banane";
      second.previous = &amp;first;
      second.next = &amp;third;
  
      third.name = "Fraise";
      third.previous = &amp;second;
      third.next = NULL;
  
      first = *(sort_files(&amp;first));
      debug(&amp;first);
      return (0);
  }
  </code></pre>