/// 冒泡排序法
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int[] arr = new int[] { 6, 1, 2, 5, 9, 11, 0, 4, 14 };
            int temp = 0;
            for (int i = 0; i < arr.Length - 1; i++)//外部循环arr的长度
            {
                for (int j = i + 1; j < arr.Length; j++)//比较大
                {
                    if (arr[j] < arr[i])//正序
                    {
                        temp = arr[i];
                        arr[i] = arr[j];
                        arr[j] = temp;
                    }
                    //if (arr[j] > arr[i])//倒叙相反显示
                    //{
                    //    temp = arr[j];
                    //    arr[j] = arr[i];
                    //    arr[i] = temp;
                    //}
                }
            }
            for (int i = 0; i < arr.Length; i++)
            {
                Console.WriteLine(arr[i]);
            }
        }

相关文章:

  • 2021-12-19
  • 2021-04-04
猜你喜欢
  • 2021-05-25
  • 2022-02-24
  • 2022-12-23
  • 2021-07-30
  • 2021-06-01
  • 2021-07-29
  • 2022-03-10
相关资源
相似解决方案