title: C Bubblesort in LinkedList
body: <p>I'm trying to sort a doubly linked list, but I'm having some trouble. I'm a noob in C and I guess my problem is with pointers..</p>
  
  <p>I just can't see how to swap two positions inside the list and so maybe that's the issue. </p>
  
  <p>I tryied to sort it by using Bubblesort, even knowing that it's complexity is not so good because, how I'm still learning, thought that it was an easy way to start.</p>
  
  <p>I also tryied reading some things about swaping elements in a linkedlist and how to sort them, but I'm really stuck with this problem...</p>
  
  <p>PS: I started the for with the m->next cause my list has a header(m).</p>
  
  <p>PS2:I'm getting the error "request for member ‘next’ in something not a structure or union", and don't know how to fix it</p>
  
  <pre><code>struct segment {
     int x, y;   /// position
     char c;   // letter 
     struct segment* next;
     struct segment* prev; 
  };
  
  
  void sortingSegments(struct segment* m) {
     struct segment **j; struct segment **i;
  
     for(i = &amp;((m-&gt;next)-&gt;next); i !=NULL; i = i-&gt;next) {
            for(j = &amp;(m-&gt;next); j == i; j = j-&gt;next) {
                if ((*j)-&gt;c &gt; (*i)-&gt;c) {
                    struct segment **aux;
                    aux = i;
                    (*aux)-&gt;next = (*i)-&gt;next;
                    (*aux)-&gt;prev = (*i)-&gt;prev;
  
                    i = j;
                    (*i)-&gt;next = (*j)-&gt;next;
                    (*i)-&gt;prev = (*j)-&gt;prev;
  
                    j = aux;
                    (*j)-&gt;prev = (*aux)-&gt;prev;
                    (*j)-&gt;next = (*aux)-&gt;next;
                }
            }
     } 
  }
  </code></pre>