title: How to reverse each half of a doubly linked list?
body: <p>I'm trying to reverse each half of a doubly linked list, lets assume the list is even and sorting doesn't matter.</p>
  
  <p>lets say I have this input,
  the list can have any even number of elements.</p>
  
  <p>1 &lt;=> 5 &lt;=> 8 &lt;=> 3 &lt;=> 2 &lt;=> 10</p>
  
  <p>This is the expected output</p>
  
  <p>8 &lt;=> 5 &lt;=> 1 &lt;=> 10 &lt;=> 2 &lt;=> 3</p>
  
  <p>I found the length of the list, to find the middle position, then I tried using a counter to go through each half,however, I feel lost once I start doing lots of while loops. I know how to reverse the whole list but I am stuck further. 
  Does anyone have any ideas?</p>
  
  <pre><code>
  
  template &lt;class T&gt;
  void DoubyLinkedList&lt;T&gt;:: ReverseFunction() {
  
  node&lt;T&gt; *ptr = head;
  
  //find length of list
  
  int length = 0;
  while (ptr!=NULL) {
  ptr = ptr-&gt;next;
  length++;
  }
  
  ptr = head;
  
  int c = 1;
  //This code reverses the whole list 
  while (ptr != NULL ) {
  
      node&lt;T&gt; *tmp = ptr-&gt;next;
  
      ptr-&gt;next = ptr-&gt;prev;
  
      ptr-&gt;prev = tmp;
  }
  
      if (tmp == NULL) {
  
          tail = head;
          head = ptr;
  
      }
      ptr = tmp;
  
  }
  
  }
  </code></pre>