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:  }
  • 相关阅读:
    css变量
    es6的this指向
    Java面试题(包装类)
    moment笔记
    Class
    CSS斜切角
    Element.getBoundingClientRect()
    Do not mutate vuex store state outside mutation handlers.
    antd不想写那么多option怎么办
    解析URL参数
  • 原文地址:https://www.cnblogs.com/djzny/p/3494398.html
Copyright © 2011-2022 走看看