最小K个数
来源:互联网 发布:php抓取百度搜索结果 编辑:程序博客网 时间:2024/05/16 15:13
#include<iostream>using namespace std;int partition(int a[],int low,int high){int prio = a[low];while (low < high){while (low < high && a[high] >= prio) high--;swap(a[high], a[low]);while (low < high && a[low] <= prio) low++;swap(a[high], a[low]);}return low;}void quicksort(int a[], int low,int high){if (low < high){int mid = partition(a, low, high);quicksort(a, 0, mid - 1);quicksort(a, mid + 1, high);}}void getLeastNum(int input[], int n, int *output, int k){int start = 0;int end = n - 1;int index = partition(input, start, end);while (index != k - 1){if (index > k - 1){end = index + 1;index = partition(input, start, end);}else{start = index + 1;index = partition(input, start, end);}}for (int i = 0; i < k; i++){output[i] = input[i];cout << input[i] << endl;}}void main(){int a[] = { 5,3,1,7,9,0,2,4,6,8 };int b[10];getLeastNum(a, 10, b, 2);/*for (int i = 0; i < 10;i++)cout << a[i] << endl;*/system("pause");}
0 0
- 最小的K个数
- 最小的K个数
- 最小的K个数
- 最小的k个数
- 最小的k个数
- 最小的k个数
- 最小的k个数
- 最小的k个数
- 最小的k个数
- 最小的K个数
- 最小的k个数
- 最小的K个数
- 最小的K个数
- 最小的K个数
- 最小的K个数
- 最小的K个数
- 最小的k个数
- 最小的k个数
- phpredis subscribe超时问题及解决
- iOS APP
- “骑驴找马”很心虚?四大困惑一起解决!
- 基于应用层自身反远程线程注入的研究
- jni简介及openSSL静态动态编译
- 最小K个数
- php mysql 应用操作数据库实例
- 如何简洁快速的在Word 2016中给公式自动编号
- Maven修改本地仓库地址
- iOS移动开发启动图广告植入
- 快速毛玻璃虚化效果实现
- kafka-topics.sh的delete命令删除topic
- HDU 2089 不要62 (数位dp)
- Node.js fs模块——读写文件