title: How to find minimum number of steps to sort an integer array
body: <p>I have an integer array  <code>int[] number = { 3,4,2,5,1};</code></p>
  
  <p>The minimum number of steps to sort it should be 2. But I am getting 4.</p>
  
  <pre><code>static void Main(string[] args)
          {
              int[] number = { 3,4,2,5,1};
  
             int result =  get_order(number);
  
              Console.ReadKey();
          }
  
          public static int get_order(int[] input1)
          {
              input1 = input1.OrderByDescending(o =&gt; o).ToArray();
              bool flag = true;
              int temp;
              int numLength = input1.Length;
              int passes = 0;
  
              for (int i = 1; (i &lt;= (numLength - 1)) &amp;&amp; flag; i++)
              {
                  flag = false;
                  for (int j = 0; j &lt; (numLength - 1); j++)
                  {
                      if (input1[j + 1] &gt; input1[j])
                      {
                          temp = input1[j];
                          input1[j] = input1[j + 1];
                          input1[j + 1] = temp;
                          flag = true;
                      }
                  }
                  passes++;
              }
              return passes+1;
          }
  </code></pre>
  
  <p>What is the problem and what changes i need to do in my code?</p>
  
  <p>Edit</p>
  
  <p>implement @Patashu, algorithm, </p>
  
  <pre><code>public static int get_order(int[] input1)
          {
              var sorterArray = input1.OrderByDescending(o =&gt; o).ToArray();
              var unsortedArray = input1;
              int temp1;
              int swap = 0;
  
              int arrayLength = sorterArray.Length;
              for (int i = 0; i &lt; arrayLength; i++)
              {
                  if (sorterArray[i] != unsortedArray[i])
                  {
                      temp1 = unsortedArray[i];
                      unsortedArray[i] = sorterArray[i];
                      for (int j = i + 1; j &lt; arrayLength; j++)
                      {
                          if (unsortedArray[j] == sorterArray[i])
                          {
                              unsortedArray[j] = temp1;
                              swap++;
                              break;
                          }
                      } 
                  }
              }
  
              return swap;
          }
  </code></pre>