title: Shifting A Circular Array
body: <p>I have a homework assignment that requires having to shift a circular array -n places in memory.</p>
  
  <p>I have accomplished the task with the following C++ Syntax:</p>
  
  <pre><code>while ( r &lt; 0 )  // rotate negatively.
  {
      if ( i == top+1 )
      {
          current-&gt;n = items[top+1].n;  
          items[top+1].n = items[back-1].n;
      }
      midPtr-&gt;n  = items[++i].n;
      items[i].n = current-&gt;n;
  
      if ( i == back-1 )
      {
              items[back-1].n = current-&gt;n;
              i = 0;
              r++; continue;
      }
      else
      {
              current-&gt;n = items[++i].n;
              items[i].n = midPtr-&gt;n;
              if ( i == back-1 )
              {
                      i = 0;
                      r++; continue;
              }
      }
  }
  </code></pre>
  
  <p>I was wondering if anyone has a better, more efficient 
  method of shifting a circular array by -n units.</p>
  
  <p>Because I seem to be performing unnecessary transfers
  between ptr variables.</p>