码迷,mamicode.com
首页 > 编程语言 > 详细

由小到大——排序结果错误!

时间:2015-08-11 08:28:36      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:

using System.Threading;

namespace 由小到大
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("输入个数:");

            int[] a = new int[int.Parse(Console.ReadLine())];

            int i = a.Length;

            for (int b = 0; b < i; b++)
            {
                Thread.Sleep(1000);

                Random r = new Random();

                a[b] = r.Next(1, 99);


                Console.Write(" " + a[b]);
            }

            Console.Write("\n由小到大");

            for (int x = 0; x < i; x++)
            {
                for (int y = 0; y < i - 1; y++)
                {
                    if (a[y] > a[y + 1])
                    {
                        int k = a[y];
                        a[y] = a[y + 1];
                        a[y + 1] = k;
                    }
                }
                Console.Write(" " + a[x]);
            }
            Console.ReadLine();

 

由小到大——排序结果错误!

标签:

原文地址:http://www.cnblogs.com/nwj-0613/p/4719917.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!