Sorting algorithms/Quicksort: Difference between revisions

Line 873:
public static void Sort(T[] entries, Int32 first, Int32 last) {
for (var i = first + 1; i <= last; i++) {
var insertentry = entries[i];
var j = i;
while (j > first && entries[j - 1].CompareTo(insertentry) > 0)
entries[j] = entries[--j];
entries[j] = insertentry;
}
}
Line 884:
}
}</lang>
'''Example''':
<lang csharp> using Sort;
using System;
 
class Program {
static void Main(String[] args) {
var entries = new Int32[] { 1, 3, 5, 7, 9, 8, 6, 4, 2 };
QuickSort<Int32>.Sort(entries);
Console.WriteLine(String.Join(" ", entries));
}
}</lang>
{{out}}
<pre>1 2 3 4 5 6 7 8 9</pre>
 
A very inefficient way to do qsort in C# to prove C# code can be just as compact and readable as any dynamic code
159

edits