插入排序方法
int[] a = { 3, 1, 5, 7, 2, 4, 9, 6 };
for (int i = 1; i < 8; i++)
{
if (a[i]<a[i-1])
{
int x = a[i];
int j;
for (j = i - 1; j>=0 && a[j] >x; j--)
{
a[j + 1] = a[j];
}
a[j+1] = x;
}
}
for (int j = 0; j < 8; j++)
{
Console.WriteLine(a[j] + ",");
}
原文:http://www.cnblogs.com/livexiaojie/p/6703068.html