zoukankan      html  css  js  c++  java
  • C# 冒泡排序

    class Program
        {
            static void swap( ref int  atemp, ref int  btemp)//注意ref的使用
            {
                int temp = atemp;
                atemp = btemp;
                btemp = temp;
            }
            static void Main(string[] args)
            {
                int temp=0;
                int[]arr={23,44,66,76,98,11,3,9,7};
                Console.WriteLine("排序前的数组:");
                foreach(int item in arr)
                {
                    Console.Write(item+" ");
                }
                Console.WriteLine();
                for(int i=0;i<arr.Length-1;i++)
                {
                    for(int j=0;j<arr.Length-1-i;j++)
                    {
                        if (arr[j] > arr[j + 1])
                              swap( ref  arr[j], ref arr[j + 1]);
                    }
                }
               Console.WriteLine("排序后的数组:");
               foreach(int item in arr)
               {
                   Console.Write(item+" ");
                }
                Console.WriteLine();
                Console.ReadKey();
     
            }
        }
  • 相关阅读:
    X
    W
    J
    A
    Q
    P
    B
    排列和组合的求解
    深度学习之序列处理
    32位和64位数据类型大小对比
  • 原文地址:https://www.cnblogs.com/rinack/p/4623979.html
Copyright © 2011-2022 走看看