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:          /// <summary>
      21:          /// 冒泡排序相当于i是确定大小的那个数,然后j是从最大开始循环,依次选一个最大或者最小的数放到索引为i的位置去
      22:          /// </summary>
      23:          /// <param name="list"></param>
      24:          /// <returns></returns>
      25:          static List<int> Sort(List<int> list)
      26:          {
      27:              int temp;
      28:              for (int i = 0; i < list.Count - 1; i++)//
      29:              {
      30:                  for (int j = list.Count - 1; j > i; j--)
      31:                  {
      32:                      if (list[j - 1] < list[j])
      33:                      {
      34:                          temp = list[j - 1];
      35:                          list[j - 1] = list[j];
      36:                          list[j] = temp;
      37:                      }
      38:                  }
      39:              }
      40:              return list;
      41:          }
      42:      }
      43:  }
  • 相关阅读:
    科学美国人(Scientific American)部分段落小译
    Matlab安装使用libsvm
    【转】Matlab中特殊符号的写法
    计算机视觉资源
    AdaBoost
    AdaBoost人脸检测原理
    NLP常用开源/免费工具(转)
    搜索背后的奥秘——浅谈语义主题计算
    求数组当中子数组最大和
    求二叉树中两个节点的最低父节点
  • 原文地址:https://www.cnblogs.com/djzny/p/3492540.html
Copyright © 2011-2022 走看看