寻找数组中第k大的数
来源:互联网 发布:魔术笔软件 编辑:程序博客网 时间:2024/05/21 11:00
#include <iostream>#include <vector>#include <algorithm>using namespace std;int partition(int arr[], int l, int r){int x = arr[r], i = l;for (int j = l; j <= r - 1; j++){if (arr[j] <= x){swap(arr[i], arr[j]);i++;}}swap(arr[i], arr[r]);return i;}int GetKth(int* a, int low, int high,int k){int pivot;if (low < high){pivot = partition(a,low,high);if ((pivot-low + 1) == k)return a[pivot];else if ((pivot-low + 1) > k)return GetKth(a,low,pivot-1,k);elsereturn GetKth(a, pivot+1,high, k);}}int main(){int a[]={1,4,6,7,98,23,24,56};int n = 8, k = 3;cout << GetKth(a,0,7,3);}
0 0
- 两个有序数组中,寻找第K大的数
- 寻找数组中第k大的数
- 寻找无序数组中第k大的数
- 寻找数组中第k大的数
- 寻找无序数组中第k大的数——快排思想
- 数组中第k大的数
- 数组中第K大的数
- 数组中第K大的数
- 寻找数列中第K大的数
- java 寻找数组中第k大的值
- java 寻找数组中第k大的值
- java 寻找数组中第k大的值
- 第k大(小)数,寻找最小的k个数(进一步要求顺序与原数组中元素顺序一致)
- 寻找第K大的数
- 寻找第K大的数
- 寻找第K大的数
- 寻找第K大的数
- 寻找第K大的数
- acm 1007 接力问题
- [转] iOS中文版资源库,非常全
- 枚举和#define宏之间的区别
- 【设计模式C++】工厂模式
- Java集合框架
- 寻找数组中第k大的数
- 简单快捷地测试 JPush API
- [BZOJ3876][Ahoi2014]支线剧情
- warning: Error opening file (../../modules/highgui/src/cap_ffmpeg_impl.hpp:545)
- IOS-60-解决:iOS7 APP页面上下有黑色间距,屏幕变小
- 'python'不是内部或外部命令,也不是可运行程序或批处理文件
- Java基础--类变量初始化顺序
- 2016年蓝桥杯javaB省赛——压缩变换
- linux sed 命令