当前位置:网站首页>选择排序法
选择排序法
2022-06-23 03:32:00 【@风景邮递Yuan】
排序需要用到的结构和函数
# define MAXSIZE 10
typedef struct {
/* 用 于 存 储 要 排 序 数 组 , r[0] 用 作 哨 兵 或 临 时 变 量 */
int r[ MAXSIZE + 1];
/* 用 于 记 录 顺 序 表 的 长 度 */
int length ;
} SqList ;
/* 交 换 L 中 数 组 r 的 下 标 为 i 和 j 的 值 */
void swap ( SqList *L, int i, int j){
int temp = L- >r[i];
L->r[i] = L- >r[j];
L->r[j] = temp ;
}选择排序序程序
每次找一个最小的数出来

/* 对 顺 序 表 L 作 简 单 选 择 排 序 */
void SelectSort ( SqList *L){
int i, j, min ;
for (i = 1; i < L- > length ; i++) {
min = i;/* 将 当 前 下 标 定 义 为 最 小 值 下 标 */
/* 循 环 之 后 的 数 据 */
for (j = i + 1; j <= L- > length ; j++) {
/* 如 果 有 小 于 当 前 最 小 值 的 关 键 字 */
if (L- >r[min ] > L- >r[j])
/* 将 此 关 键 字 的 下 标 赋 值 给 min */
min = j;
}
if (i != min )
/* 若 min 不 等 于 i , 说 明 找 到 最 小 值 */
/* 交 换L->r[i] 与L- >r[min ] 的 值 */
swap (L, i, min );
}
}边栏推荐
- Simple analysis of easygbs compatible with old version HLS streaming address method [with code]
- [burning] Tencent cloud high tech computing platform HTPC cloud elastic cluster release!
- Form submit onclick and onsubmit
- 2022-01-22: Li Kou 411, the abbreviation of the shortest exclusive word. Give a string number
- Tencent released the global DDoS threat report in 2021: DDoS threat has become the preferred extortion method for criminal gangs
- [advanced Android] kotlin delegate attribute
- "Tencent conference": how to operate and maintain efficiently in the face of exponential growth of business?
- Google Earth Engine(GEE)——长时间序列逐月VCI数据提取分析和面积计算(墨西哥为例)
- 1058 multiple choice questions (20 points)
- What is the difference between ArrayList and LinkedList?
猜你喜欢

JS Part 4

mysql常用指令

Analysis on the development of China's graphene industry chain in 2021: with the support of energy conservation and environmental protection policies, the scale of graphene industry will continue to e

innodb_ruby 视角下 MySQL 记录增删改

【owt】owt-client-native-p2p-e2e-test vs2017构建2 :测试单元构建及运行

Encryption related to returnee of national market supervision public service platform

【机器学习】 吴恩达机器学习作业 ex2逻辑回归 Matlab实现

Analysis on the development of China's satellite navigation industry chain in 2021: satellite navigation is fully integrated into production and life, and the satellite navigation industry is also boo

第一批00后下场求职:不要误读他们的“不一样”

【owt】owt-client-native-p2p-e2e-test vs2017构建 4 : 第三方库的构建及链接p2pmfc.exe
随机推荐
直接插入排序
【owt】owt-client-native-p2p-e2e-test vs2017构建 3 : 无 测试单元对比, 手动生成vs项目
Decentralized networks are not decentralized
纳瓦尔宝典:不靠运气致富的原则
Tencent cloud tcapulusdb helps tmeland, the first virtual Music Carnival in China, and tens of thousands of people cross the new year together!
TDesign update weekly report (the second week of January 2022)
How to print array contents
MIT 6. S081/fall 2020 build risc-v and xv6 development and debugging environment
Is LinkedList a one-way linked list or a two-way linked list?
If there is a smart bus visualization platform, can "beginning" restart indefinitely?
Customization of openfeign
SwiftUI 组件大全之使用 ScrollView 和 GeometryReader 创建动画 3D卡片 滚动效果
Form submit onclick and onsubmit
Evolution of cloud firewall products
Simple analysis of easygbs compatible with old version HLS streaming address method [with code]
Analysis on the development of duty-free industry in Hainan Province in 2021: the implementation of the new policy makes the duty-free market in Hainan more "prosperous" [figure]
Easysearcher cannot find the IP address of easynvr hardware. How to solve it?
How to share small programs released by wechat
Analysis on the development of China's graphene industry chain in 2021: with the support of energy conservation and environmental protection policies, the scale of graphene industry will continue to e
[Alibaba middleware technology series] "Nacos technology" service registration and discovery related principle analysis