title: Reverse function for a doubly linked list
body: <p>If I send my reverse function on a list I get the expected output. But if I use my reverseNth function I only get the first thing in my list. ReverseNth reverses the list in sections.
  For example if I have a list = &lt;1 2 3 4 5>. Calling reverse() will output &lt;5 4 3 2 1>. Calling reverseNth(2) on the list should give &lt;2 1 4 3 5>. </p>
  
  <p>Relevant Code:</p>
  
  <pre><code>void List&lt;T&gt;::reverse( ListNode * &amp; startPoint, ListNode * &amp; endPoint )
  {
      if(startPoint == NULL || startPoint == endPoint)
          return;
      ListNode* stop = endPoint;
      ListNode* temp = startPoint;
      startPoint = endPoint;
      endPoint = temp;
      ListNode* p = startPoint; //create a node and point to head
  
      while(p != stop)
      {
          temp = p-&gt;next;
          p-&gt;next = p-&gt;prev;
          p-&gt;prev = temp;
          p = p-&gt;next;
      }
  }
  </code></pre>
  
  <p>ReverseNth code:</p>
  
  <pre><code>void List&lt;T&gt;::reverseNth( int n )
  {
      if(head == NULL || head == tail || n == 1 || n == 0)
          return;
  
      if(n &gt;= length)
      {
          reverse(head,tail);
          return;
      }
  
      ListNode* tempStart = head;
      ListNode* tempEnd;
  
      for(int j = 0; j &lt; length; j += n)
      {
          // make the end of the section the beginning of the next
          tempEnd = tempStart;
          // set the end of the section to reverse
          for(int i = 0; i &lt; n-1; i ++)
          {
              // check to make sure that the section doesn't go past the length
              if(j+i == length)
                  i = n; 
              else
                  tempEnd = tempEnd-&gt; next;
          }
  
          reverse(tempStart, tempEnd);
  
          if( j == 0)
              head = tempStart;
          if(tempStart == tail)
          {
              tail = tempEnd;
              return;
          }
          else
              tempStart = tempEnd-&gt; next;
      }
      tail = tempEnd;
  }
  </code></pre>