zoukankan
html css js c++ java
算法 排序 直接选择排序(Straight Selection Sort)
void
SelectSort(SeqList R)
{
int
i,j,k;
for
(i
=
1
; i
<
n; i
++
)
{
//
做第i趟排序(1≤i≤n-1)
k
=
i;
for
(j
=
i
+
1
; j
<=
n; j
++
)
//
在当前无序区R[i..n]中选key最小的记
录R[k]
{
if
(R[j].key
<
R[k].key)
{
k
=
j;
//
k记下目前找到的最小关键字所在的位置
}
}
if
(k
!=
i)
{
//
交换R[i]和R[k]
R[temp]
=
R[i];
R[i]
=
R[k];
R[k]
=
R[temp];
//
R[temp]作暂存单元
}
//
endif
}
//
endfor
}
//
SeleetSort
void
SelectSort(
int
[] x)
{
for
(
int
i
=
0
; i
<
x.Length
-
1
; i
++
)
{
//
只需做n-1次循环
int
min
=
i;
for
(
int
j
=
i
+
1
; j
<
x.Length; j
++
)
{
if
(x[j]
<
x[min])
{
min
=
j;
}
}
if
(min
!=
i)
{
//
交换x[i]和x[k]
int
temp;
temp
=
x[i];
x[i]
=
x[min];
x[min]
=
temp;
}
//
endif
}
//
endfor
}
//
SelectSort
查看全文
相关阅读:
React中autoComplete="off" 失效
git配置文件—— .editorconfig
git配置文件—— .gitattributes
配置文件—— .travis.yml
python入门:常用模块—sys模块
python入门:常用模块—random模块
python入门:常用模块—time & datetime模块
python入门:常用模块—模块,包介绍
Python入门:生成器&迭代器
python入门:函数进阶(名称空间,闭包,装饰器)
原文地址:https://www.cnblogs.com/xiaodi/p/296499.html
最新文章
linux文件系统概述
linux的进程管理
linux下的用户组管理
linux下的用户管理(二)
DAY39
DAY38
DAY37
DAY36
DAY35
git基础知识
热门文章
DAY34
DAY33
DAY32
mysql数据库入门
webpack2.0配置postcss-loader
git 查看/修改用户名和邮箱地址
Android Studio
react-native 相对项目路径导入组件 ___ babel-plugin-module-resolver
react-native 相对项目路径导入组件 ___ babel-plugin-root-import
http状态码_____ 204/206/200
Copyright © 2011-2022 走看看