c#数组排序

来源:互联网 发布:富士国际语学院 知乎 编辑:程序博客网 时间:2024/05/16 17:47


            c#读入与写出我只知道如下代码这种,所以很多方面都感觉没c++方便,排序函数要自己写,还不知道c#有什么函数可用,有没有排序函数,还有c++的头文件之类的都用不了了,郁闷!!!!!


using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace MyFirstAPP{    class Program    {        static void sort(int[] a,int n)        {            int i,j;            for(i=0;i<n;++i)            {                for (j = i + 1; j < n;++j )                {                    if (a[i] > a[j])                    {                        a[i] ^= a[j];                        a[j] = a[i] ^ a[j];                        a[i] = a[j] ^ a[i];                    }                }            }        }        static void Main(string[] args)        {            Console.WriteLine("请输入一个数:");            int n = Convert.ToInt32(Console.ReadLine());            int[] a = new int[n];            Console.WriteLine("请输入{0}个数",n);            for (int i = 0; i < n;++i)            {                a[i] = Convert.ToInt32(Console.ReadLine());            }            sort(a,n);            for (int i = 0; i < n;++i)            {                Console.Write("{0} ",a[i]);            }            Console.WriteLine();        }    }}


0 0