// 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; using System.Collections.Generic; namespace E { public class QS { private static void SortHelp(int n1, int n2, IList lst) where T : IComparable { int l = n1; int r = n2; T pivot = lst[(n1 + n2) / 2]; do { while (lst[l].CompareTo(pivot) < 0) l++; while (lst[r].CompareTo(pivot) > 0) r--; if (l <= r) { T tmp = lst[l]; lst[l] = lst[r]; lst[r] = tmp; l++; r--; } } while (l <= r); if (n1 < r) SortHelp(n1, r, lst); if (l < n2) SortHelp(l, n2, lst); return; } public static void Sort(IList lst) where T : IComparable { SortHelp(0, lst.Count - 1, lst); } } public class Program { public static void Main(string[] args) { IList lst1 = new List { 4, 1, 3, 2 }; QS.Sort(lst1); foreach (int iv in lst1) { Console.WriteLine(iv); } IList lst2 = new List { "DDDD", "A", "CCC", "BB" }; QS.Sort(lst2); foreach (string sv in lst2) { Console.WriteLine(sv); } } } }