欢迎访问我的博客 https://javascript.shop

排序 选择排序

原文发布时间为:2009-03-06 —— 来源于本人的百度文章 [由搬家工具导入]

using System;

namespace sorts
{
    public class Class6
    {
        public static void Main() //选择排序
        {
            int[] a = new int[] { 1, 4, 3, 9, 5, 4 };
            SelectSort(a);
            for (int i = 0; i < a.Length; i++)
                Console.Write("{0} ", a[i]);
            Console.ReadLine();
        }

        public static void SelectSort(int[] arr)
        {
            for (int i = 0; i < arr.Length - 1; i++)
            {
                int min = i;
                for (int j = i + 1; j < arr.Length; j++)
                {
                    if (arr[j] < arr[min])
                    {
                        min = j;
                    }
                }
                int temp = arr[min];
                arr[min] = arr[i];
                arr[i] = temp;
            }
        }

    }
}

posted @ 2017-07-12 00:05  孑孓子  阅读(85)  评论(0编辑  收藏  举报
欢迎访问我的博客 https://javascript.shop