zoukankan      html  css  js  c++  java
  • 冒泡排序算法示例

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 冒泡排序1
    {
        class Program
        {
            static void Main(string[] args)
            {
                //将下面数组按由大到小排列,使用冒泡排序法
                int[] ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14 };
                //冒泡排序
                for (int i = 0; i < ints.Length; i++)//遍历多少次
                {
                    for (int j = 0; j < ints.Length-i-1; j++)//趟数-1-次数
                    {
                        if (ints[j]<ints[j+1])//如果前一个数字小于后一个数字
                        {
                            int temp = ints[j];//将小的数字存在中间变量
                            ints[j] = ints[j + 1];//交换数字
                            ints[j + 1] = temp;
                        }
                    }
                }
                //遍历输出
                foreach (var item in ints)
                {
                    Console.WriteLine(item);
                }
            }
        }
    }
    
  • 相关阅读:
    晨考总结第二天
    晨考总结第一天
    常用的设计模式总结
    AOP底层原理剖析
    Spring AOP
    jstat统计输出说明
    zabbix 触发器匹配字符串告警
    hive部分常用函数
    nginx日志说明
    windwos文件句柄数限制
  • 原文地址:https://www.cnblogs.com/ypfnet/p/2888282.html
Copyright © 2011-2022 走看看