快排
来源:互联网 发布:海绵城市知乎 编辑:程序博客网 时间:2024/04/29 12:17
//快排#include<iostream>#include<cstdlib>using namespace std;void QuickSort(int *a, int l, int r){int lt = l, rt = r;int md = (l + r) / 2;int f = a[(l + r) / 2];//int mid = a[md];while (lt < rt){while (a[lt] < f)lt++;while (a[rt] > f)rt--;if (lt <= rt){int temp = a[lt];a[lt] = a[rt];a[rt] = temp;lt++;rt--;}}if (lt == rt){lt++;}if (lt < r)QuickSort(a, rt + 1, r);if (rt > l)QuickSort(a, l, lt - 1);}int main(){int a[10] = { 3,5,9,8,0,1,2,7,6,10 };int n = 10;for (int i = 0; i < 10; i++)cout << a[i] << " ";cout << endl;QuickSort(a, 0, 9);for (int i = 0; i < 10; i++)cout << a[i] << " ";system("pause");return 0;}
阅读全文
0 0
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排
- 快排。
- No resource found that matches the given name (at 'layout_above' with value '@id/butt
- elasticsearch 编程api 2
- 2017开学训练第七周周末总结
- 时间序列预测分析:以NASDAQ指数为例
- 按位与、或、异或等的相关操作
- 快排
- 第1章 数据库简介
- JavaScript01-变量类型与计算
- elasticsearch 编程api 1
- javascript超时调用和间歇调用
- php 递归删除目录
- 新反向代理与负载均衡工具 traefik 安装配置部署详解
- 2.1电商项目的订单系统
- SSM(SpringMVC,Spring.Mybatis)构建Web项目.环绕通知,时间转换,DES,MD5,拦截器