冒泡排序

 

          int[] nums = { 1, 4, 3, 9, 6, 8, 11 };
            //只能针对数组做一个升序的排列
             //// Array.Sort(nums);
             ////Array.Reverse (nums );
            //对数组进行反转
       for (int i = 0; i < nums.Length - 1; i++)
            {
                for (int j = 0; j < nums.Length - 1 - i; j++)
                {
                    if (nums[j] < nums[j + 1])
                    {
                        int temp = nums[j];
                        nums[j] = nums[j + 1];
                        nums[j + 1] = temp;
                    }
                }
            }
            for (int i = 0; i < nums.Length; i++)
            {
                Console.WriteLine(nums[i]);
            }

 

posted @ 2017-11-21 15:58  wb_enduo  阅读(94)  评论(0编辑  收藏  举报