c++快速排序
2016-01-23 15:49
239 查看
快速排序(n个数) 从数中随便选取一个数a,(一般选取第一个数),将a与其余的数字s进行比较,若a小于s,则交换。n-1轮比较完成后。 另选一个数a,与其余n-2数分别比较,(交换),如此重复, 进行N-1轮比较。 // kspx2.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include<iostream> using namespace std; void kspx(int a[10]){ int temp; for(int i=0;i<9;i++){ for(int j=i+1;j<9;j++){ if(a[i]>a[j]){ temp=a[i]; a[i]=a[j]; a[j]=temp; } } } } int _tmain(int argc, _TCHAR* argv[]) { int a[10]={4,5,6,2,1,3,0,7,9,8}; cout<<"before:"<<endl; for(int i=0;i<10;i++){ cout<<a[i]<<" "; } kspx(a); cout<<endl<<"after:"<<endl; for(int i=0;i<10;i++){ cout<<a[i]<<" "; } cout<<endl; system("pause"); return 0; }
相关文章推荐
- C语言 生成随机数
- c/c++中的sort()与qsort()用法
- 学习笔记--内核中C语言和汇编的使用
- 2413: C语言习题 折半查找
- live555ProxyServer.cpp分析:初始化流程
- C++ typedef typename 作用
- c++冒泡排序算法
- c语言递归调用:买啤酒
- 按位dp初步
- x265-1.7版本-encoder/weightPrediction.cpp注释
- 「C语言」「概念」数据类型及混合运算与类型转换
- C++ 在.h文件中包含头文件和在.cpp文件中包含头文件有什么区别?
- x265-1.7版本-encoder/slicetype.cpp注释
- c++ 设计模式3 (重构技法 Template Method)
- x265-1.7版本-encoder/motion.cpp注释
- C++如何确定常量的类型
- C语言 数字转换为字符串
- C++ 运算符优先级
- x265-1.7版本-encoder/frameencoder.cpp注释
- C\C++中转义字符集锦