• 自娱自乐之选择排序


       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:  }
  • 相关阅读:
    2013.10.21—2013.10.25周总结
    2013.10.14—2013.10.18周总结
    2013.10.8—2013.10.12周总结
    MongoDb的“not master and slaveok=false”错误及解决方法,读写分离
    python 获取当前时间
    git命令与github使用
    s​s​h​配​置​公​钥​和​私​钥​登​陆​S​e​c​u​r​e​C​R​T
    关于pydev的语法的错误提示
    lnmp1.0 升级php.5.4.28 后出错 Nginx 502 Bad Gateway
    python线程Example
  • 原文地址:https://www.cnblogs.com/djzny/p/3492763.html
Copyright © 2020-2023  润新知