码迷,mamicode.com
首页 > 编程语言 > 详细

排序 选择排序

时间:2017-07-12 10:25:57      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:new   sort   int   color   namespace   static   pac   names   style   

原文发布时间为: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;
            }
        }

    }
}

排序 选择排序

标签:new   sort   int   color   namespace   static   pac   names   style   

原文地址:http://www.cnblogs.com/handboy/p/7153254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!