C#把一个int数组的数字从小到大排列

using System;

namespace ConsoleApplication1
{
    ///


    /// Class1 的摘要说明。
    ///

    class Class1
    {
        ///
        /// 应用程序的主入口点。
        ///

        [STAThread]
        static void Main(string[] args)
        {
            MinToMax mtm = new MinToMax();
            int[] array = { 1, 2, 6, 3, 8, 3, 4, 0, 5, 23, 52, 12, 234, 235, 1232, 21, 234, 123, 143, 1368 };
            int[] last = mtm.MTM(array);
            int n = 0;
            for (int i = 0; i < array.Length; i++)
            {
                System.Console.Write(last[i] + "<");
                ++n;

            }
            System.Console.WriteLine("\n总共{0}个数字", n);

            System.Console.ReadLine();
            //
            // TODO: 在此处添加代码以启动应用程序
            //
        }
    }

    public class MinToMax
    {
        public int[] MTM(int[] array)
        {
            int[] FianlMTM = new int[array.Length];

            for (int j = 0; j < array.Length; j++)
            {
                int last = 0;
                for (int i = 1; i < array.Length - j; i++)
                {
                    int t = array[i];

                    if ((array[i]) < (array[i - 1]))
                    {

                        array[i] = array[i - 1];
                        last = array[i];
                        array[i - 1] = t;

                    }
                    else
                        last = array[i];

 

                }
                FianlMTM[array.Length - (j + 1)] = last;

            }
            return FianlMTM;

        }
    }
}

 

 

你可能感兴趣的:(C,C++,C#,J#)