2016年c#冒泡排序

来源:互联网 发布:电视挂墙高度知乎 编辑:程序博客网 时间:2024/06/05 09:28
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace consoleapplication1{    class Program    {        static void Main(string[] args)        {            int[] a = new int[10];            string s;            for(int i=0;i<10;i++)            {                   s=Console.ReadLine();                a[i] = int.Parse(s);            }            for (int i = 0; i < 10; i++)            {                for (int j = 0; j < 10 - i - 1; j++)                {                    if (a[j] > a[j + 1])                    {                        int t;                        t = a[j];                        a[j] = a[j + 1];                        a[j + 1] = t;                    }                }            }            for (int i = 0; i < 10; i++)            {                Console.Write(a[i]);                Console.Write(" ");            }            Console.ReadKey();        }    }}

0 0
原创粉丝点击