zoukankan      html  css  js  c++  java
  • C# 经典算法 冒泡排序法(正序,倒序)

     /// 冒泡排序法
            /// </summary>
            /// <param name="args"></param>
            static void Main(string[] args)
            {
                int[] arr = new int[] { 6, 1, 2, 5, 9, 11, 0, 4, 14 };
                int temp = 0;
                for (int i = 0; i < arr.Length - 1; i++)//外部循环arr的长度
                {
                    for (int j = i + 1; j < arr.Length; j++)//比较大
                    {
                        if (arr[j] < arr[i])//正序
                        {
                            temp = arr[i];
                            arr[i] = arr[j];
                            arr[j] = temp;
                        }
                        //if (arr[j] > arr[i])//倒叙相反显示
                        //{
                        //    temp = arr[j];
                        //    arr[j] = arr[i];
                        //    arr[i] = temp;
                        //}
                    }
                }
                for (int i = 0; i < arr.Length; i++)
                {
                    Console.WriteLine(arr[i]);
                }
            }

  • 相关阅读:
    常用模块
    二分查找算法
    递归函数
    文件操作
    day02--Python基础二(基础数据类型)
    Python学习笔记day01--Python基础
    Python2X和Python3X的区别
    testdisk修复文件系统
    机器学习入门 快速版
    tableau教程 快速入门
  • 原文地址:https://www.cnblogs.com/huangxuening/p/2623141.html
Copyright © 2011-2022 走看看