public void Sort(T[] data, ISwapStrategy <T> strategy) { if (data == null) { throw new ArgumentNullException(); } int maxDist = 1; while (maxDist < (data.Length / 3)) { maxDist = 3 * maxDist + 1; } for (int d = maxDist; d > 0; d = d / 3) { for (int i = d; i < data.Length; i = i + d) { int index = i; for (int j = i - d; j >= 0; j = j - d) { if (data[index].CompareTo(data[j]) >= 0) { break; } strategy.Swap(data, index, j); index = j; } } } }
public void Sort(T[] data, ISwapStrategy <T> strategy) { _sortingThread = new Thread(delegate() { _sorterInternal.Sort(data, strategy); }); _sortingThread.Start(); }
public void Sort(T[] data, ISwapStrategy <T> strategy) { if (data == null) { throw new ArgumentNullException(); } _strategy = strategy; _copy = new T[data.Length]; SortTopDown(data, 0, data.Length / 2, data.Length - 1); //SortBottomUp(data); }
public void Sort(T[] data, ISwapStrategy <T> strategy) { if (data == null) { throw new ArgumentNullException(); } for (int i = 0; i < data.Length; i++) { for (int j = i; j < data.Length; j++) { if (((IComparable <T>)data[i]).CompareTo(data[j]) > 0) { strategy.Swap(data, i, j); } } } }
public void Sort(T[] data, ISwapStrategy <T> strategy) { for (int i = 0; i < data.Length; i++) { int index = i; for (int j = i - 1; j >= 0; j--) { if (data[index].CompareTo(data[j]) >= 0) // If data[i] is greate then or equals the previous one, then it is in order { break; } // Else, swap the data[i] with the previous one,until it is greater than the previous one. strategy.Swap(data, index, j); index = j; } } }
public void Sort(T[] data, ISwapStrategy <T> strategy) { if (data == null) { throw new ArgumentNullException(); } for (int i = 0; i < data.Length; i++) { int min = i; for (int j = i; j < data.Length; j++) { if (((IComparable <T>)data[j]).CompareTo((data[min])) < 0) { min = j; } } strategy.Swap(data, i, min); } }