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:  }
  • 相关阅读:
    Zabbix 配置笔记
    Centos7安装MySQL5.7和Redis6.0流水账
    Elasticsearch, Kibana安装
    服务治理 Service Mesh & Kubernetes & Spring Cloud的异同 侵入式 非侵入式
    文思海辉 华为 银行 ODS (oCRM)
    Java Profiler JavaMemoryLeak Arthas
    动物:人类、熊类、马类 团队精神 与 鼓励
    BPMN Sketch Miner https://design.inf.usi.ch/bpmn-sketch-miner/#
    Architecture, Design and Web Information Systems Engineering
    Cloud design patterns
  • 原文地址:https://www.cnblogs.com/djzny/p/3494398.html
Copyright © 2011-2022 走看看