title: What is the most elegant way of shell sorting (comb / diminishing increment sorting) in C#?
body: <p>Is there a better way to shell sort using C#?</p>
  
  <pre><code>// array of integers to hold values
  private int[] a = new int[100];
  
  // number of elements in array
  private int count;
  
  // Shell Sort Algorithm
  public void sortArray()
  {
    int i, j, increment, temp;
  
    increment = 3;
  
    while( increment &gt; 0 )
    {
      for( i=0; i &lt; count; i++ )
      {
        j = i;
        temp = a[i];
  
        while( (j &gt;= increment) &amp;&amp; (a[j-increment] &gt; temp) )
        {
          a[j] = a[j - increment];
          j = j - increment;
        }
  
        a[j] = temp;
      }
  
      if( increment/2 != 0 )
      {
        increment = increment/2;
      }
      else if( increment == 1 )
      {
        increment = 0;
      }
      else
      {
        increment = 1;
      }
    }
  }
  </code></pre>
  
  <p>By the way, I'm wondering because I have some different examples of 'elegant' sorts in different languages (like bubble sorting in <a href="https://stackoverflow.com/questions/1595244/whats-the-most-elegant-way-to-bubble-sort-in-c">C#</a> and <a href="https://stackoverflow.com/questions/279145/what-is-the-most-elegant-way-of-bubble-sorting-in-f">F#</a>), and I'm comparing them. In real life, I'd probably use the following most of the time in C#:</p>
  
  <pre><code>Array.Sort( object[] )
  </code></pre>
  
  <p>I don't care if these are 'academic' and non-pragmatic patterns. You can down-mod me into oblivion if you want :)</p>
  
  <p>KA</p>