public static T Select(T[] a, int k, IComparer c) { StdRandom.Shuffle(a); int lo = 0, hi = a.Length - 1; while (lo < hi) { int j = Partition(a, lo, hi, c); if (j < k) { lo = j + 1; } else if (j > k) { hi = j - 1; } else { return(a[k]); } } return(a[k]); }
public static void Sort(T[] a) { StdRandom.Shuffle(a); Sort(a, 0, a.Length - 1); }
public static void Sort(T[] a, IComparer c) { StdRandom.Shuffle(a); Sort(a, 0, a.Length - 1, c); }