S1 冒泡排序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Win_eight
{
    class Program
    {
        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 < 5; i++)
            {
                Console.WriteLine("{0}\t",scores[i]);
            }
            Console.ReadLine();
        }
    }
}

冒泡排序速记口诀(升序):

1、N个数字来排队,两辆相比小靠前。

2、外层循环N-1,内层循环N-1-I。

3、如果要降序排序,只要把程序中的大于号换成小于号就行了。

原文地址:https://www.cnblogs.com/xiaoqiaccp/p/2752328.html