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

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

  • 相关阅读:
    [LeetCode] Contains Duplicate II
    [LeetCode] House Robber II
    [LeetCode] Permutations II
    [LeetCode] Permutations
    [LeetCode] Next Permutation
    谈谈套接字
    基于Linux系统的Nagios网络管理模块的实现
    Windows/Linux下磁盘使用的图形化工具简介
    利用日志使管理Linux更轻松
    实际感受美丽的Linux(多组视频)
  • 原文地址:https://www.cnblogs.com/zhengguangITelite/p/2482260.html
Copyright © 2011-2022 走看看