博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
快速排序C++代码
阅读量:4598 次
发布时间:2019-06-09

本文共 954 字,大约阅读时间需要 3 分钟。

#include 
using namespace std;template
void qSort(T *a, int left, int right);// 快速排序template
void sW(T *a, T *b);int main(){ int a[] = {3, 4, 5, 12, -1, -33, 90, -44, -23, 100, -1111, -9}; int len = sizeof(a)/sizeof(int); cout << *(a+1); cout << "原始数据:" << endl; for(int i = 0; i
void qSort(T *a, int left, int right){ const int len = right; while(left < right){ while( *(a+left) < *(a+right) && left < right ) --right; // 以输入队列的第一个数为Key,自右向左寻找比key小的数,当前数不比key小则--right sW(a+left, a+right); while( *(a+left) < *(a+right) && left < right ) ++left; // 从左向右找比key大的数,找到后交换 sW(a+left, a+right); qSort(a, 0, left-1); qSort(a, left+1, len); }}template
void sW(T *a, T *b){ T temp; temp = *a; *a = *b; *b = temp;}

 

转载于:https://www.cnblogs.com/TTYF/p/9108013.html

你可能感兴趣的文章
linux常用端口
查看>>
异常处理
查看>>
/proc/uptime详解
查看>>
如何建立合适的索引?
查看>>
acwing 651. 逛画展
查看>>
(待完成)qbxt2019.05 总结12 - 趣味题目 鹰蛋
查看>>
[2018/11/18] Java数据结构(2) 简单排序 冒泡排序 选择排序 插入排序
查看>>
关于WPF程序只运行一个实例的方法
查看>>
游标的使用
查看>>
图论:点分治
查看>>
mysql
查看>>
C/C++ 知识点---sizeof使用规则及陷阱分析(网摘)
查看>>
java小程序 示例
查看>>
前端开发在线小工具
查看>>
有关cookies使用方法
查看>>
Hadoop 使用Combiner提高Map/Reduce程序效率
查看>>
前言 转录组
查看>>
扫描图片怎么转换成文字
查看>>
easyui刷新渲染
查看>>
kindeditor 引用js架包问题
查看>>