using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] a = { 118, 101, 105, 127, 112 };
InsertSort(a);
Console.ReadLine();
}
static void InsertSort(int[] array)
{
int j, t;
for (int i = 1; i < array.Length; i++)
{
t = array[i];
j = i - 1;
while (j >= 0 && t < array[j])
{
array[j + 1] = array[j];
j--;
}
array[j + 1] = t;
Console.WriteLine("第" + i + "步排序结果");
for (int h = 0; h < array.Length; h++)
{
Console.Write(" " + array[h].ToString());
}
Console.WriteLine();
}
}
}
}
![image image]()