首页 > 代码库 > 数组冒泡排序

数组冒泡排序

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace maopao{    class Program    {        static void Main(string[] args)        {            int[] nums = new int[10];            Console.Write("输入十个整数:\n");            for (int i = 0; i < 10; i++)            {                nums[i] = int.Parse(Console.ReadLine());            }            int temp = 0;            for (int j = 0; j < 9; j++)            {                for (int i = 0; i < 9 - j; i++)                    if (nums[i] > nums[i + 1])                    {                        temp = nums[i];                        nums[i] = nums[i + 1];                        nums[i + 1] = temp;                    }            }            Console.WriteLine("排序的结果为:\n");            for (int i = 0; i < 10; i++)            {                Console.Write("{0}{1}", nums[i], ' ');            }            Console.ReadLine();        }    }}

数组冒泡排序