首页 > 其他 > 详细

C#输入排序-冒泡

时间:2014-02-13 02:43:47      阅读:305      评论:0      收藏:0      [点我收藏+]
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MP
{    
     class Pro
    {
        public void f(int n)
        {
            int[] a = new int[n];
            int i = 0, temp, j = 0;
            for (i = 0; i < n; i++)
            {
                a[i] = Int32.Parse(Console.ReadLine());
                if(i==n-1)
                {
                    Console.WriteLine("start:");
                    break;
                }
            }
            for (i = 0; i < a.Length - 1; i++)
            {
                for (j = 0; j < a.Length - i - 1; j++)
                {
                    if (a[j] > a[j + 1])
                    {
                        temp = a[j];
                        a[j] = a[j + 1];
                        a[j + 1] = temp;
                    }
                }
            }
            for (i = 0; i < a.Length; i++)
            {
                Console.WriteLine(a[i]);
            }
        }
        static void Main(string[] args)
        {
            Pro p = new Pro();
            int k = Int32.Parse(Console.ReadLine());
            p.f(k);
            Console.ReadKey();
        }
    }
}

C#输入排序-冒泡

原文:http://www.cnblogs.com/HorseKing/p/3546393.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!