冒泡排序

class Program
    {
        static int[] arry = new int[6];       
        static void Main(string[] args)
        {
            for (int i = 0; i < arry.Length; i++)
            {
                arry[i] = i*2 + 1;          
            }
            int temp = 0;
            for (int i = 0; i < arry.Length-1; i++)
            {
                for (int j = i + 1; j < arry.Length; j++)
                {
                    if (arry[j] < arry[i])
                    {
                        temp = arry[j];
                        arry[j] =arry[i];
                        arry[i] = temp;
                    }
                }
            }
            for (int i = 0; i < arry.Length; i++)
            {
                Console.WriteLine(arry[i]);
            }
            Console.WriteLine("Press any key to exit..");
            Console.ReadLine();
        }
    }
posted @ 2009-07-13 18:17  大有  阅读(227)  评论(0)    收藏  举报