title: shell sort pseudocode to C++ code
body: <pre><code># Sort an array a[0...n-1].
  gaps = [701, 301, 132, 57, 23, 10, 4, 1]
  
  foreach (gap in gaps)
      # Do an insertion sort for each gap size.
      for (i = gap; i &lt; n; i += 1)
          temp = a[i]
          for (j = i; j &gt;= gap and a[j - gap] &gt; temp; j -= gap)
              a[j] = a[j - gap]
          a[j] = temp
  </code></pre>
  
  <p>this is the pseudocode in <a href="http://en.wikipedia.org/wiki/Shellsort#Pseudocode" rel="nofollow">Wikipedia</a> page.
  I'm not sure about that if my c++ code is correct according to it. Here is my code:</p>
  
  <pre><code>void shellSort(int *array, int array_size)
  {
    int e, i, j, temp;
    for(e = 0; e &lt; array_size; e++)
    {
        for( i = e; i &lt; array_size; i++)
        {
            temp = array[i];
            for( j = i; j &gt;= e &amp;&amp; array[j - e] &gt; temp; j -= e)
            {
               array[j] = array[j-e];
            }
            array[j] = array[temp];
        }
  
    }
  }
  </code></pre>
  
  <p>And here is my test code:</p>
  
  <pre><code>int main()
  {
      int sizes[9] = {9,3,5,7,1,0,6,2,4};
      int size = 0;
      shellSort(sizes,size);
  
      for(int i=0;i&lt;size;i++)
      {
          cout &lt;&lt; sizes[i] &lt;&lt; endl;
      }
  
  return 0;
  
  }
  </code></pre>
  
  <p>but it shows nothing on the screen.</p>