直接插入排序

来源:互联网 发布:青少年违法犯罪数据 编辑:程序博客网 时间:2024/05/21 17:51
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;                }                        }        }    }}

原创粉丝点击