函数——数组排序

namespace 函数冒泡排序
{
    class Program
    {
     
        static void Main(string[] args)
        {
            int[] b = new int[5] { 1,5,3,4,2};

            new Program().Array(b);   //数组b调用已经写好的Array函数用来排序

            for (int i = 0; i < b.Length; i++)
            {
                Console.WriteLine(b[i]);
            }
            Console.ReadLine();
           
        } //主函数的花括号

//Array函数
        public int[] Array(int[] a)
        {  
            int n = a.Length;
            for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n-i; j++)
                {
                    int temp=0;
                    if(a[j-1]<a[j])
                    {
                        temp = a[j - 1];
                        a[j - 1] = a[j];
                        a[j] = temp;
                    }
                }
            }
            return a;
        }
    }
}

原文地址:https://www.cnblogs.com/lk-kk/p/4420591.html