数组的排序

来源:互联网 发布:html5media.min.js 编辑:程序博客网 时间:2024/06/11 22:03
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arry = new int[10] { 2, 5, 8, 4, 6, 1, 3, 9, 7,0 };
            int temp;//中介数
            for (int i = 0; i < arry.Length; i++) 
            {
                for(int j=0;j<arry.Length;j++)//arry.Length为数组长度
                {
                    if(arry[i]<arry[j])
                    {
                        temp = arry[i];//俩个数的交换
                        arry[i] = arry[j];//
                        arry[j] = temp;//
                    }
                }
            }
            foreach (int n in arry)
                Console.Write(n);
            Console.Write("\n");
        }
    }
}
原创粉丝点击