直接插入排序
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; } } } } }