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

推荐订阅源

The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
B
Blog
小众软件
小众软件
T
Tailwind CSS Blog
MyScale Blog
MyScale Blog
I
InfoQ
Engineering at Meta
Engineering at Meta
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
H
Help Net Security
雷峰网
雷峰网
S
SegmentFault 最新的问题
V
Visual Studio Blog
爱范儿
爱范儿

博客园 - L.Zhang

.Net Remoting RMI框架 自己开发连接池 JDBC访问数据库 MyEclipse下开发Web Service 使用传统的XMLHttpRequest发出Ajax请求 XML CDATA XPath 数据库操作的sql脚本 直接插入排序 气泡排序 Builder 生成器模式(创建型模式) Abstract Factory 抽象工厂模式(创建型模式) Factory Method 工厂方法模式(创建型模式) Singleton单件模式(创建型模式) 使用Profile Service 服务端如何使用Session 让服务端返回xml 用Get方式访问
直接选择排序
L.Zhang · 2007-11-02 · via 博客园 - L.Zhang

namespace SelectSort
{
    
public partial class frmMain : Form
    {
        
struct rectype
        {
            
public int key;
            
public string other;
        }
private rectype[] r;
        
private const int n = 10;/// <summary>
        
/// 构造函数
        
/// </summary>
        public frmMain()
        {
            InitializeComponent();

            r 

= new rectype[n];

            Random ran 

= new Random();for (int i = 0; i < n; i++)
            {
                r[i].key 
= ran.Next(100);
                r[i].other 
= "我是" + r[i].key;
                
this.lbUnSort.Items.Add(r[i].other);
            }
        }
/// <summary>
        
/// 开始排序
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>
        private void btnSort_Click(object sender, EventArgs e)
        {
            
this.SELECTSORT();for (int i = 0; i < n; i++)
            {
                
this.lbSort.Items.Add(r[i].other);
            }

        }

/// <summary>
        
/// 排序算法
        
/// </summary>
        private void SELECTSORT()
        {
            
int i, j, k;
            rectype temp;
for (i = 0; i < n - 1; i++)
            {
                k 
= i;
                
for (j = i + 1; j < n; j++)
                {
                    
if (r[j].key < r[k].key)
                    {
                        k 
= j;
                    }
                }
if (k != i)
                {
                    temp 
= r[i];
                    r[i] 
= r[k];
                    r[k] 
= temp;
                }
            }
        }
    }
}