简单选择排序(C/C++实现)
来源:互联网 发布:普通话考试准备软件 编辑:程序博客网 时间:2024/05/17 03:30
#include <iostream>using namespace std;#define MAXSIZE 10typedef struct{ int data[MAXSIZE+1]; //data[0]作为哨兵 int length;}SqList;void Swap(SqList *L, int i, int j){ int tmp; tmp = L->data[i]; L->data[i] = L->data[j]; L->data[j] = tmp;}void SelectSort(SqList *L){ int i, j; int min; for(i=1; i<L->length; i++) { min = i; for(j=i+1; j<=L->length; j++) { if(L->data[j] < L->data[min]) { min = j; } } if(i != min) { Swap(L, i, min); //找到最小的数然后进行交换 } }}int main(){ int i; SqList list; cout <<"Please input " <<MAXSIZE<<" number :" << endl; for(i=0; i<MAXSIZE; i++) { cin >> list.data[i+1]; } list.length = MAXSIZE; cout <<"The numbers before sort: "; for(i=0; i<MAXSIZE; i++) { cout << list.data[i+1] << " "; } cout << endl; SelectSort(&list); cout <<"The numbers after sort: "; for(i=0; i<MAXSIZE; i++) { cout << list.data[i+1] << " "; } cout << endl; return 0;}
0 0
- 简单选择排序(C & Java 实现)
- 简单选择排序(C语言实现)
- 简单选择排序(C/C++实现)
- 排序算法(C实现)--------- 简单选择排序
- 排序之三:简单选择排序(C语言实现)
- 简单选择排序(C)
- 【算法】简单选择排序C语言实现
- C 简单选择排序
- 数据结构 简单选择排序(C语言实现)
- 选择排序C实现
- C实现选择排序
- C语言实现冒泡排序和简单选择排序
- 简单选择排序(C语言版本)
- (排序)用C语言实现的简单选择排序(选择排序,其实个人认为也是交换排序)
- C++ 简单选择排序
- c语言简单选择排序
- 蛮力法之选择排序(C实现)
- 选择排序(C语言实现)
- 品质管理核心
- "伪中国移动客户端"--伪基站诈骗
- 搭建一个基于OSGI的可以运行helloworld.html和helloworld.jsp的简单web环境
- Making User-Managed Backups-17.4、Making User-Managed Backups of Online Tablespaces and Datafiles
- repo upload 时报错
- 简单选择排序(C/C++实现)
- 杭电 Palindromes _easy version
- Android Loader
- 中国邮票
- 《学习opencv》笔记——矩阵和图像操作——cvGertDims,cvGetDimSize,cvGetRow,cvGetRow,cvGetSize and cvGetSubRect
- Swift简介 教程
- winpcap学习笔记--(Capturing the packets without the callback)
- 用OpenSceneGraph实现的NeHe OpenGL教程 - 第四十六课
- Linux下查看文件和文件夹大小