直接插入排序的算法
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 直接插入排序
{
class Program
{
static void Main(string[] args)
{
int[] org = new int[2];
int i, j ;
Console.Write("输入待排序元素:\n");
for ( i = 0; i <org.Length; i++)
{ org[i] =Convert.ToInt32( Console.ReadLine()); }
for (i = 1; i < org.Length; i++)
if(org[i ]<org[i-1])
{ int love = org[i];
for (j = i; j > 0 && org[j - 1] > love; j--)
{ org[j] = org[j - 1]; }
org[j] = love
;
}
Console.WriteLine("-------输出结果---------");
for( i=0;i<org.Length;i++)
{ Console.WriteLine( org[i]+"\t" )
;
}
Console.ReadLine();
}
}
}