private int Partition(TrainList a, int p, int r) { Train x = a[p]; int i = p - 1; int j = r + 1; while (true) { do { j--; }while (cmp(a[j], x) > 0); do { i++; }while (cmp(a[i], x) < 0); if (i < j) { Train tmp = a[i]; a[i] = a[j]; a[j] = tmp; } else { return(j); } } }
private TrainList QuickSort(TrainList a, int left, int right) { if (left < right) { int q = Partition(a, left, right); a = QuickSort(a, left, q); a = QuickSort(a, q + 1, right); } return(a); }
public TrainSortAndFind(string fieldForCompare, TrainList trains) { this.fieldForCompare = fieldForCompare ?? throw new ArgumentNullException(nameof(fieldForCompare)); this.trains = trains ?? throw new ArgumentNullException(nameof(trains)); }