• 自娱自乐之冒泡排序


       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:  }
  • 相关阅读:
    抛开BlazeDS,自定义flex RPC
    设计模式学习03装饰器模式
    通过ANT生成MANIFEST.MF中的ClassPath属性
    Spring JDBCTemplate与Hiberante混用
    关于 两个 datetime 列的差别导致了运行时溢出
    在Wcf中使用Nhibernate (续)
    sql2005/sql2008 分页
    工行支付api查询asp.net C# 实现
    生成静态页面的vbscript
    Asp.net Mvc Post ID Bug
  • 原文地址:https://www.cnblogs.com/djzny/p/3492540.html
Copyright © 2020-2023  润新知