快速SELECT算法
来源:互联网 发布:网络盒子怎么连接电视 编辑:程序博客网 时间:2024/05/17 13:06
#include <iostream>#include <algorithm>using namespace std;int a[] = {4, 3, 6, 8, 10, 9, 2, 5, 7, 1};void select(int a[], int lhs, int rhs, int k){if(lhs > rhs || k < 0)return;int i = lhs, j = rhs, pivot = a[lhs];while(i < j){while(a[j] >= pivot && i < j)j--;while(a[i] <= pivot && i < j)i++;if(i < j){int t = a[i];a[i] = a[j];a[j] = t;}}if(i == j){a[lhs] = a[i];a[i] = pivot;for(int l = 0; l < 10; ++l)cout << a[l] << " ";cout << endl;if(i-lhs> k)select(a, lhs, i - 1, k);else if(i-lhs < k)select(a, i + 1, rhs, k - i + lhs - 1);elsereturn;}return;}int main(void){int k = 7;//7select(a, 0, 9, k);for(int i = 0; i < k; ++i)cout << a[i] << " ";cout << endl;return 0;}
0 0
- 快速SELECT算法
- 快速选择select算法
- 快速选择SELECT算法实现
- 快速选择SELECT算法的实现
- 【编程练习】快速select算法的实现
- 读书笔记:"算法导论"之RANDOMIZED-SELECT(快速选择算法)
- 读书笔记:"算法导论"之RANDOMIZED-SELECT(快速选择算法)
- 快速选择SELECT算法的深入分析与实现
- 快速排序与快速选择算法(quick sort and quick select algorithm)
- 快速选择 randomized select
- 十四、第三章再续:快速选择SELECT算法的深入分析与实现
- 十四、亦第三章再续:快速选择SELECT算法的深入分析与实现
- 十四、第三章再续:快速选择SELECT算法的深入分析与实现
- 十四、第三章再续:快速选择SELECT算法的深入分析与实现
- 十四、第三章再续:快速选择SELECT算法的深入分析与实现
- 快速算法
- 快速算法
- Python:SELECT 排序算法
- 危险的森林里你最不希望遇到的是什么动物
- 写好SCI论文的语言技巧 之 学术英语的表达 Academic English
- 使用cocoapods添加的库和不支持arm64的API真机调试问题
- Linux下区分物理CPU、逻辑CPU和CPU核数
- html 的基础知识
- 快速SELECT算法
- 浅谈项目管理——《项目管理修炼之道》读后感
- 九度_题目1519:合并两个排序的链表
- pthread_create()给创建的线程传递参数
- 求归属于ID下的所有ID
- 网络
- 丢失了两元钱的车这只是一个故事吗
- 设计模式13—Bridge设计模式
- ssd的写放大