以Int类型数组为举例
namespace 直接插入排序
{
class Program
{ private static void Insert(int[] arrayList)
{
bool isInsert = false;
for (int i = ; i < arrayList.Length; i++)
{
int value = arrayList[i];
for (int j = i-; j >= ; j--)
{
if (arrayList[j] > value)
{
arrayList[j + ] = arrayList[i];
}
else
{
//发现一个比i小的值,
arrayList[j+] = value;
isInsert = true;
break; }
if (isInsert == false)
{
arrayList[] = value;
} }
} } static void Main(string[] args)
{
int[] data = new[] {, , , , , };
Insert(data);
foreach (var temp in data)
{
Console.WriteLine(temp+" ");
}
Console.ReadKey();
}
}
}