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

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

  • 相关阅读:
    【Java8】 @FunctionalInterface 函数式接口
    集合使用copy与mutableCopy的区别
    GCD中的dispatch_sync、dispatch_sync 分别与串行、并行队列组合执行小实验
    podspec文件介绍
    iOS系统app崩溃日志手动符号化
    webView文本长按显示英文
    深拷贝
    view向全屏延伸时的属性设置
    iOS 模拟器截屏快捷键
    mysql 优化常用语句
  • 原文地址:https://www.cnblogs.com/zhengguangITelite/p/2482260.html
Copyright © 2011-2022 走看看