您的位置:首页 > 其它

选择排序之从小到大排序

2016-07-31 14:24 148 查看
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace 选择排序

{

    class Program

    {

        static void Main(string[] args)

        {

            int[] s = new int[10] { 10, 36, -55, 5, 0, 14, -416, -1236, 14, 39 };

            int num;

            int index;

            for (int i = 0; i < s.Length - 1; i++)

            {

                num = s[i];

                index = i;

                for (int j = i + 1; j < s.Length; j++)

                {

                    if (num > s[j])

                    {

                        num = s[j];

                        index = j;

                    }

                }

                int temp;

                temp = s[i];

                s[i] = num;

                s[index] = temp;

            }

            for (int i = 0; i < s.Length; i++)

            {

                Console.Write(s[i] + " ");

            }

            Console.ReadKey();

        }

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: