直接插入排序
class Program
{
static void Main(string[] args)
{
int[] array = { 4, 6, 34, 75, 43, 7, 356, 2 };
InsertSort(array);
for (int i = 0; i < array.Length; i++)
{
Console.Write(array[i] + " ");
}
Console.ReadKey();
}
public static void InsertSort(int[] arr)//直接插入排序
{
for (int i = 1; i < arr .Length; i++)
{
for (int j = i; j > 0; j--)
{
if (arr [j] < arr [j - 1])
{
int temp = arr [j];
arr [j] = arr [j - 1];
arr [j - 1] = temp;
}
}
}
}
}