// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; public class QS { private static void qsint_help(int n1, int n2, int[] ia) { int tmp; int l = n1; int r = n2; int pivot = ia[(n1 + n2) / 2]; do { while (ia[l] < pivot) l++; while (ia[r] > pivot) r--; if (l <= r) { tmp = ia[l]; ia[l] = ia[r]; ia[r] = tmp; l++; r--; } } while (l <= r); if (n1 < r) qsint_help(n1, r, ia); if (l < n2) qsint_help(l, n2, ia); return; } public static void qsint(int[] ia) { qsint_help(0, ia.Length - 1, ia); return; } } class MainClass { public static void Main(string[] args) { int[] a1 = { 10, 2, 4, 7, 3, 1, 5, 8, 9, 6 }; int[] a2 = (int[])a1.Clone(); int[] a3 = (int[])a1.Clone(); Array.Sort(a2); QS.qsint(a3); for(int i = 0; i < a1.Length; i++) { Console.WriteLine(a1[i] + " " + a2[i] + " " + a3[i]); } } }