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

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

  • 相关阅读:
    垃圾回收于内存优化(摘自网络)
    as3.0 动态改变影片剪辑的颜色
    2进制_8进制_16进制之间快速转换的技巧.txt
    24位真彩色转换为8位灰度图片(完整代码)
    大端模式和小端模式
    如何将真彩色图转换为各种灰度图
    C++图像缩放
    二进制转十进制快速转换方法
    电脑上运行的使用大全
    移位运算符详解
  • 原文地址:https://www.cnblogs.com/zhengguangITelite/p/2482260.html
Copyright © 2011-2022 走看看