日期:2014-05-17  浏览次数:21028 次

c#交换排序 找不到错误 求高手改改
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TextHello
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j = 0;
            int[] a = { 1, 2, 4, 5, 3 };
            for (i = 0; i < 5; i++)
            {
                int temp;
                while (j < 5)
                {
                    if (a[i] > a[i + 1])
                    {
                        temp = a[i];
                        a[i] = a[i + 1];
                        a[i + 1] = temp;
                        j++;

                    }
                }

            }
            for (int x = 0; x < 5; x++)
            {
                System.Console.WriteLine("第{0}个元素是{1}", x + 1, a[x]);
            }