private void Sort(IList list, int fromPos, int toPos, object[] scratch) { if (fromPos >= toPos) { return; } var mid = (fromPos + toPos) / 2; Sort(list, fromPos, mid, scratch); Sort(list, mid + 1, toPos, scratch); var tLow = fromPos; var tHigh = mid + 1; int i; for (i = fromPos; i <= toPos; i++) { if (tLow <= mid) { if (tHigh > toPos) { scratch[i] = list[tLow]; tLow++; } else { if (Comparer.Compare(list[tLow], list[tHigh]) < 0) { scratch[i] = list[tLow]; tLow++; } else { scratch[i] = list[tHigh]; tHigh++; } } } else { scratch[i] = list[tHigh]; tHigh++; } } for (i = fromPos; i <= toPos; i++) { Swapper.Set(list, i, scratch[i]); } }
private void Sort(IList list, int fromPos, int toPos, object[] scratch) { int mid = 0; int i; int t_low; int t_high; if (fromPos < toPos) { mid = (fromPos + toPos) / 2; Sort(list, fromPos, mid, scratch); Sort(list, mid + 1, toPos, scratch); t_low = fromPos; t_high = mid + 1; for (i = fromPos; i <= toPos; i++) { if (t_low <= mid) { if (t_high > toPos) { scratch[i] = list[t_low]; t_low++; } else { if (Comparer.Compare(list[t_low], list[t_high]) < 0) { scratch[i] = list[t_low]; t_low++; } else { scratch[i] = list[t_high]; t_high++; } } } else { scratch[i] = list[t_high]; t_high++; } } for (i = fromPos; i <= toPos; i++) { Swapper.Set(list, i, scratch[i]); } } }
internal void InsertionSort(IList list, int lo0, int hi0) { int i; for (i = lo0 + 1; i <= hi0; i++) { var v = list[i]; var j = i; while (j > lo0 && (Comparer.Compare(list[j - 1], v) > 0)) { Swapper.Set(list, j, j - 1); j--; } list[j] = v; } }
public override void Sort(IList list) { int i; for (i = 1; i < list.Count; i++) { var j = i; var b = list[i]; while (j > 0 && (Comparer.Compare(list[j - 1], b) > 0)) { Swapper.Set(list, j, list[j - 1]); --j; } Swapper.Set(list, j, b); } }
public override void Sort(IList list) { int h; int i; int j; object b; bool loop = true; h = 1; while (h * 3 + 1 <= list.Count) { h = 3 * h + 1; } while (h > 0) { for (i = h - 1; i < list.Count; i++) { b = list[i]; j = i; loop = true; while (loop) { if (j >= h) { if (Comparer.Compare(list[j - h], b) > 0) { Swapper.Set(list, j, j - h); j = j - h; } else { loop = false; } } else { loop = false; } } Swapper.Set(list, j, b); } h = h / 3; } }
public override void Sort(IList list) { int i; int j; object b; for (i = 1; i < list.Count; i++) { j = i; b = list[i]; while ((j > 0) && (Comparer.Compare(list[j - 1], b) > 0)) { Swapper.Set(list, j, list[j - 1]); --j; } Swapper.Set(list, j, b); } }
public override void Sort(IList <T> list) { var h = 1; while (h * 3 + 1 <= list.Count) { h = 3 * h + 1; } while (h > 0) { int i; for (i = h - 1; i < list.Count; i++) { var b = list[i]; var j = i; var loop = true; while (loop) { if (j >= h) { if (Comparer.Compare(list[j - h], b) > 0) { Swapper.Set(list, j, j - h); j = j - h; } else { loop = false; } } else { loop = false; } } Swapper.Set(list, j, b); } h = h / 3; } }
private void Sort(IList list, int fromPos, int toPos) { int end_low; int start_high; int i; object tmp; int mid; if (fromPos < toPos) { mid = (fromPos + toPos) / 2; Sort(list, fromPos, mid); Sort(list, mid + 1, toPos); end_low = mid; start_high = mid + 1; while (fromPos <= end_low & start_high <= toPos) { if (Comparer.Compare(list[fromPos], list[start_high]) < 0) { fromPos++; } else { tmp = list[start_high]; for (i = start_high - 1; i >= fromPos; i--) { Swapper.Set(list, i + 1, list[i]); } Swapper.Set(list, fromPos, tmp); fromPos++; end_low++; start_high++; } } } }
private void Sort1(IList list, int fromPos, int toPos) { var low = fromPos; var high = toPos; if (high - low <= 16) { Sort2(list, low, high); } else { var pivot = list[(low + high) / 2]; list[(low + high) / 2] = list[high]; list[high] = pivot; while (low < high) { while (Comparer.Compare(list[low], pivot) <= 0 & low < high) { low++; } while (Comparer.Compare(pivot, list[high]) <= 0 & low < high) { high--; } if (low < high) { Swapper.Swap(list, low, high); } } Swapper.Set(list, toPos, high); Swapper.Set(list, high, pivot); Sort1(list, fromPos, low - 1); Sort1(list, high + 1, toPos); } }