• 冒泡排序算法示例


    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);
                }
            }
        }
    }
    
  • 相关阅读:
    oracle中 connect by prior 递归算法
    sql优化__rownum的使用【转】
    ASP.NET Core四大部件
    .net core Socket
    .NET Core 配置文件
    .NET Core IOC AOP
    Quartz.Net—MisFire
    Quartz.Net—配置化
    Quartz.Net—IJob特性
    Quartz.Net—DateBuilder
  • 原文地址:https://www.cnblogs.com/ypfnet/p/2888282.html
Copyright © 2020-2023  润新知