using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Main
{
public static void InsertionSortAscending(this IList<sbyte> i_List)
{//from ww w . j a va2s . com
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 InsertionSortAscending(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 InsertionSortAscending(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 InsertionSortAscending(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 InsertionSortAscending(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 InsertionSortAscending(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 InsertionSortAscending(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 InsertionSortAscending(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 InsertionSortAscending(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;
}
}
}
#region Specialised primitive numerical type InsertionSort varients
public static void InsertionSortAscending(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;
}
}
}
}
No comments