zoukankan      html  css  js  c++  java
  • 自娱自乐之选择排序

       1:  using System;
       2:  using System.Collections.Generic;
       3:  using System.Linq;
       4:  using System.Text;
       5:   
       6:  namespace ConsoleApplication6
       7:  {
       8:      class Program
       9:      {
      10:          static void Main(string[] args)
      11:          {
      12:              List<int> list = new List<int>() { 565, 5, 5, 4156, 15, 6, 84, 641, 5, 4, 98 };
      13:              list = Sort(list);
      14:              foreach (int i in list)
      15:              {
      16:                  Console.Write(i + " ");
      17:              }
      18:              Console.ReadLine();
      19:          }
      20:   
      21:          /// <summary>
      22:          /// 选择排序的原理就是依次循环数据,然后再通过一个循环找出当前最小的数或者最大的数,然后赋值给第一次循环的索引
      23:          /// </summary>
      24:          /// <param name="list"></param>
      25:          /// <returns></returns>
      26:          static List<int> Sort(List<int> list)
      27:          {
      28:              int temp = 0;
      29:              int baseNum = 0;
      30:              for (int j = 0; j < list.Count - 1; j++)
      31:              {
      32:                  temp = j;
      33:                  for (int i = j + 1; i < list.Count; i++)
      34:                  {
      35:                      if (list[temp] < list[i])
      36:                          temp = i;
      37:                  }
      38:                  baseNum = list[temp];
      39:                  list[temp] = list[j];
      40:                  list[j] = baseNum;
      41:              }
      42:              return list;
      43:          }
      44:      }
      45:  }
  • 相关阅读:
    Shortcut key for WPF
    Make webclient support upload the large file which are larger than 1G
    Decodes a QuotedPrintable encoded string
    C# USB Detection winform and WPF
    [转] 线程同步
    C# x86应用x64系统上读取x64位应用的注册表
    CSS Sprites图片拼合生成器实现思路
    python 复制文件
    Resources: Tips of Notepad++
    ASP.net MVC与RESTful ROA的思想还是有点区别的
  • 原文地址:https://www.cnblogs.com/djzny/p/3492763.html
Copyright © 2011-2022 走看看