title: Reversing Doublely Linked Deque in C
body: <p>I'm having trouble reversing my doublely linked deque list (with only a back sentinel) in C, I'm approaching it by switching the pointers and here is the code I have so far:</p>
  
  <pre><code>/* Reverse the deque
  
   param:  q  pointer to the deque
   pre: q is not null and q is not empty
   post:  the deque is reversed
  */
  /* reverseCirListDeque */
  void reverseCirListDeque(struct cirListDeque *q)
  {
   struct DLink *back = q-&gt;backSentinel;
   struct DLink *second = q-&gt;backSentinel-&gt;prev;
   struct DLink *third = q-&gt;backSentinel-&gt;next;
  
   while (second != q-&gt;backSentinel-&gt;next){
    back-&gt;next = second;
    third = back-&gt;prev;
    back-&gt;next-&gt;prev = back;
    back = second;
    second = third;
   }
  }
  </code></pre>
  
  <p>But it doesn't seem to work, I've been testing it with a deque that looks like this: 1, 2, 3
  The output is: 3   and this process seems to mess up the actual value of the numbers.  ie. 2 becomes 2.90085e-309... I think the pointer switching is messed up but I cannot find the problem. And even though it doesn't mean my code is correct; it compiles fine.</p>