您的位置:首页 > 编程语言 > C#

直接插入排序

2013-11-13 20:08 501 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Insertsort
{
class Program
{
static void Main(string[] args)
{
int [] x = { 6, 2, 4, 1, 5, 8,12,5,8,45 };
insertsort(x);
foreach (var item in x)
{
if (item > 0)
Console.WriteLine(item + ",");
}
Console.ReadLine();

}
public static void insertsort(int[] data)
{
int count = data.Length;
for (int j = 1; j < count; j++)
{
int x = data[j];
int i = j - 1;
while(i >= 0 && x < data[i])
{
data[i + 1] = data[i];
i = i - 1;
data[i +1] = x;
}

}
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# 插入排序