惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
腾讯CDC
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
V
V2EX
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
量子位
F
Fortinet All Blogs
G
Google Developers Blog
T
The Blog of Author Tim Ferriss
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
T
Tailwind CSS Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
D
Docker
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
Jina AI
Jina AI
M
MIT News - Artificial intelligence
博客园 - 【当耐特】

博客园 - gxc

C#2.0中的泛型约束(转载) 解决‘“System.Configuration.ConfigurationSettings.AppSettings”已过时’的警告 《雷神之锤III》里求平方根倒数的函数 回溯法(vc)百鸡百钱问题 回溯法(vc)八皇后问题 六十六条经典禅语 prototype.js和Ajax 悖论 标签的使用(2) 标签的使用(1) 自底向上的归并排序 自顶向下的归并排序 归并排序之归并算法 Josephus问题(循环链表) 找质数算法(Sieve of Eratosthenes筛法) 堆排序 快速排序算法 Some of the new features from ASP.NET 2.0 在ASP.NET中使用AJAX
直接选择排序
gxc · 2005-12-23 · via 博客园 - gxc

直接选择排序的思想是:每次从无序数组中选出一个最小的出来,放到已排好序的数组的最后。
它比起冒泡排序有一个优点就是不用不断的交换,但是冒泡排序有一个选择排序不具有的好处,就是当某趟扫描没有发生交换的时候便可以终止算法。
public static void SELECTSORT(int[] R)
{   
    for (int i = 0; i < R.Length-1; i++)
    {
        int index = i;
        for (int j = i + 1; j < R.Length; j++)
        {
            if (R[j] < R[index])
            {
                index = j;
            }
        }
        //交换R[i]和R[index]
         if (index != i)
        {
            int t = R[i]; R[i] = R[index]; R[index] = t;
        }
    }   
}