zoukankan      html  css  js  c++  java
  • 自娱自乐之直接插入排序

       1:  using System;
       2:  using System.Collections.Generic;
       3:  using System.Linq;
       4:  using System.Text;
       5:  using System.Diagnostics;
       6:  using System.Threading;
       7:   
       8:  namespace ConsoleApplication6
       9:  {
      10:      class Program
      11:      {
      12:          static void Main(string[] args)
      13:          {
      14:              List<int> list = new List<int>();
      15:   
      16:              //插入2w个数字
      17:              for (int i = 0; i < 100; i++)
      18:              {
      19:                  Thread.Sleep(1);
      20:                  list.Add(new Random((int)DateTime.Now.Ticks).Next(0, 1000));
      21:              }
      22:   
      23:              Sort(list);
      24:              Console.WriteLine("输出前十个数" + string.Join(",", list.Take(100).ToList()));
      25:   
      26:              Console.Read();
      27:   
      28:          }
      29:   
      30:          /// <summary>
      31:          /// 将需要排序的索引位置先用一个临时变量存储起来,然后依次将数腾开,将其放到相应的索引位置去
      32:          /// </summary>
      33:          /// <param name="list"></param>
      34:          public static void Sort(List<int> list)
      35:          {
      36:              for (int i = 0; i < list.Count; i++)
      37:              {
      38:                  int temp = list[i];
      39:                  int j = i;
      40:                  for (; j > 0 && temp > list[j - 1]; j--)
      41:                      list[j] = list[j - 1];
      42:                  list[j] = temp;
      43:              }
      44:          }
      45:      }
      46:  }
  • 相关阅读:
    java页面请求跑批处理sql的有关问题
    Linux下一个检查跑批是否成功的Shell
    redhat Linux5 安装vsftp .
    LINUX FTP简单配置
    java代理机制
    详细解析Java中抽象类和接口的区别
    抽象类和接口的区别
    SVN与Git比较
    浅谈存储过程和触发器
    存储过程,触发器,函数 学习总结
  • 原文地址:https://www.cnblogs.com/djzny/p/3494398.html
Copyright © 2011-2022 走看看