CSharp examples for Data Structure Algorithm:Sort
Insertion Sort Descending
using System.Collections.Generic; public class Main{ public static void InsertionSortDescending(this IList<sbyte> i_List) {// ww w. ja va 2 s .co m int size = i_List.Count; for (int index = 1; index < size; ++index) { int readIndex = index - 1; sbyte examinedValue = i_List[index]; //early break test for quicker processing of almost sorted arrays if (i_List[readIndex] < examinedValue) { while ((readIndex >= 0) && (i_List[readIndex] < examinedValue)) { i_List[readIndex + 1] = i_List[readIndex]; --readIndex; } i_List[readIndex + 1] = examinedValue; } } } public static void InsertionSortDescending(this IList<ushort> i_List) { int size = i_List.Count; for (int index = 1; index < size; ++index) { int readIndex = index - 1; ushort examinedValue = i_List[index]; //early break test for quicker processing of almost sorted arrays if (i_List[readIndex] < examinedValue) { while ((readIndex >= 0) && (i_List[readIndex] < examinedValue)) { i_List[readIndex + 1] = i_List[readIndex]; --readIndex; } i_List[readIndex + 1] = examinedValue; } } } public static void InsertionSortDescending(this IList<uint> i_List) { int size = i_List.Count; for (int index = 1; index < size; ++index) { int readIndex = index - 1; uint examinedValue = i_List[index]; //early break test for quicker processing of almost sorted arrays if (i_List[readIndex] < examinedValue) { while ((readIndex >= 0) && (i_List[readIndex] < examinedValue)) { i_List[readIndex + 1] = i_List[readIndex]; --readIndex; } i_List[readIndex + 1] = examinedValue; } } } public static void InsertionSortDescending(this IList<ulong> i_List) { int size = i_List.Count; for (int index = 1; index < size; ++index) { int readIndex = index - 1; ulong examinedValue = i_List[index]; //early break test for quicker processing of almost sorted arrays if (i_List[readIndex] < examinedValue) { while ((readIndex >= 0) && (i_List[readIndex] < examinedValue)) { i_List[readIndex + 1] = i_List[readIndex]; --readIndex; } i_List[readIndex + 1] = examinedValue; } } } public static void InsertionSortDescending(this IList<byte> i_List) { int size = i_List.Count; for (int index = 1; index < size; ++index) { int readIndex = index - 1; byte examinedValue = i_List[index]; //early break test for quicker processing of almost sorted arrays if (i_List[readIndex] < examinedValue) { while ((readIndex >= 0) && (i_List[readIndex] < examinedValue)) { i_List[readIndex + 1] = i_List[readIndex]; --readIndex; } i_List[readIndex + 1] = examinedValue; } } } public static void InsertionSortDescending(this IList<short> i_List) { int size = i_List.Count; for (int index = 1; index < size; ++index) { int readIndex = index - 1; short examinedValue = i_List[index]; //early break test for quicker processing of almost sorted arrays if (i_List[readIndex] < examinedValue) { while ((readIndex >= 0) && (i_List[readIndex] < examinedValue)) { i_List[readIndex + 1] = i_List[readIndex]; --readIndex; } i_List[readIndex + 1] = examinedValue; } } } public static void InsertionSortDescending(this IList<double> i_List) { int size = i_List.Count; for (int index = 1; index < size; ++index) { int readIndex = index - 1; double examinedValue = i_List[index]; //early break test for quicker processing of almost sorted arrays if (i_List[readIndex] < examinedValue) { while ((readIndex >= 0) && (i_List[readIndex] < examinedValue)) { i_List[readIndex + 1] = i_List[readIndex]; --readIndex; } i_List[readIndex + 1] = examinedValue; } } } public static void InsertionSortDescending(this IList<long> i_List) { int size = i_List.Count; for (int index = 1; index < size; ++index) { int readIndex = index - 1; long examinedValue = i_List[index]; //early break test for quicker processing of almost sorted arrays if (i_List[readIndex] < examinedValue) { while ((readIndex >= 0) && (i_List[readIndex] < examinedValue)) { i_List[readIndex + 1] = i_List[readIndex]; --readIndex; } i_List[readIndex + 1] = examinedValue; } } } public static void InsertionSortDescending(this IList<float> i_List) { int size = i_List.Count; for (int index = 1; index < size; ++index) { int readIndex = index - 1; float examinedValue = i_List[index]; //early break test for quicker processing of almost sorted arrays if (i_List[readIndex] < examinedValue) { while ((readIndex >= 0) && (i_List[readIndex] < examinedValue)) { i_List[readIndex + 1] = i_List[readIndex]; --readIndex; } i_List[readIndex + 1] = examinedValue; } } } public static void InsertionSortDescending(this IList<int> i_List) { int size = i_List.Count; for (int index = 1; index < size; ++index) { int readIndex = index - 1; int examinedValue = i_List[index]; //early break test for quicker processing of almost sorted arrays if (i_List[readIndex] < examinedValue) { while ((readIndex >= 0) && (i_List[readIndex] < examinedValue)) { i_List[readIndex + 1] = i_List[readIndex]; --readIndex; } i_List[readIndex + 1] = examinedValue; } } } }