当前位置:   article > 正文

冒泡排序-fusha

冒泡排序-fusha

冒泡排序-fusha

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("冒泡排序算法演示:--------------------");
            int[] Text = { 5, 8, 2, 11, 20, 1, 3, 6 };
            bubble_sort(ref Text);
            for (int i = 0; i < Text.Length; i++)
            {
                Console.WriteLine("冒泡排序结果:"+Text[i]);
            }
            Console.ReadLine();
        }
      public  static void bubble_sort(ref int [] ary )//冒泡排序函数
        {
            int temp;
            for (int i = 0; i < ary.Length; i++)//总有多少个数就换值判断多少次,确保每一次都是正确的。第一个值小于第二个值。
            {
                for (int j = i+1; j < ary.Length; j++)
                {
                    if (ary[j]<ary[i])//判断第二个数是否小于第一个数,如果是则发生换值。
                    {
                        temp = ary[j];
                        ary[j] = ary[i];
                        ary[i] = temp;
                    }
                }
            }
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/338989
推荐阅读
相关标签
  

闽ICP备14008679号