title: index out of range in insertion sort in c#
body: <p>I am doing sorting of 10 random numbers generated and have to do sorting in step by step in a gui. but in an insertion sort when i press button for sorting it gives the problem of index out of range i know its giving problem bcoz of i_ins++ but i can't remove it also bcoz my sorting in gui won't be step by step so any solution or modification to this that it will run step by step and won't give an error also.</p>
  
  <pre><code>    public void InsertionSort()
      {
  
          int j;
          int c_value;
  
          c_value = generate[i_ins];
          j = i_ins - 1;
  
          while (j &gt;= 0 &amp;&amp; generate[j] &gt; c_value)
          {
              generate[j + 1] = generate[j];
              show1(generate);
              j--;
          }
  
          generate[j + 1] = c_value;
          i_ins++;
  
          show1(generate);
      }
  </code></pre>