zoukankan      html  css  js  c++  java
  • 冒泡排序

    static void Main(string[] args)
            {
                int[] scores = new int[5];
                int i,j;
                int temp;
                Console.WriteLine("请输入5个学员的成绩:");
                for (i = 0; i < 5; i++)
                {
                    Console.WriteLine("请输入第{0}个学员的成绩",i + 1);
                    scores[i] = int.Parse(Console.ReadLine());
                }

                for (i = 0; i < scores.Length -1; i++)
                {
                    for (j = 0; j < scores.Length -1 - i; j++)
                    {
                        if (scores[j] > scores[j+1])
                        {
                            temp = scores[j];
                            scores[j] = scores[j+1];
                            scores[j + 1] = temp;
                        }
                    }
                }
                Console.WriteLine("排序后:");
                for (i = 0; i < scores.Length; i++)
                {
                    Console.WriteLine("{0}\t",scores[i]);
                }
                Console.ReadLine();
            }

    口诀(升序):

    N个数字来排序,两两相比小靠前

    外层循环 I-1,内存循环 I-1-J

    如果要降序,只把大于换小于

  • 相关阅读:
    linux下的磁盘挂载
    shell中的循环语句while
    hadoop安装和配置
    shell 命令 创建/删除 软连接 ln -s
    azkaban disable 停用部分工作流
    git dev 分支merge到master
    shell 命令 zip unzip
    git代码同步服务器代码需要注意的问题
    shell 命令 if elif else fi 用法
    python 引入本地 module
  • 原文地址:https://www.cnblogs.com/zhengguangITelite/p/2482260.html
Copyright © 2011-2022 走看看