c#希尔排序与直接插入排序算法效率对比代码
代码语言:c#
所属分类:其他
代码描述:c#希尔排序与直接插入排序算法效率对比代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Diagnostics; namespace HelloWorldApplication { public class HelloWorld { static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.Unicode; //5次比较 for (int i = 1; i <= 2; i++) { List < int > list = new List < int > (); //插入1w个随机数到数组中 for (int j = 0; j < 100; j++) { Thread.Sleep(1); list.Add(new Random((int)DateTime.Now.Ticks).Next(10000, 1000000)); } List < int > list2 = new List < int > (); list2.AddRange(list); Console.WriteLine("\n第" + i + "次比较:"); Stopwatch watch = new Stopwatch(); watch.Start(); InsertSort(list); watch.Stop(); Console.WriteLine("\n插入排序耗费的时间:" + watch.ElapsedMilliseconds); Console.WriteLine("输出前十个数:" + string.Join(",", list.Take(10).ToList())); watch.Restart(); ShellSort(list2); watch.Stop(); Console.WriteLine("\n希尔排序耗费的时间:" + watch.ElapsedMilliseconds); Console.WriteLine("输出前十个数:" + string.Join(",", list2.Take(10).To.........完整代码请登录后点击上方下载按钮下载查看
网友评论0