#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;
const int N = 7;
int SecondSmall(int a[], int n);
void FindTwo(int a[], int i, int j, int &fmin1, int &fmin2);
int FindK(int a[], int n, int k);
void Swap(int &left, int &right);
int Select(int a[], int left, int right, int k);
int main ()
{
int a[N] = {2, 4, 1, 6, 5, 9, 0};
//cout << SecondSmall(a, N) << " is the second small number" << endl;
int k = 3;
cout << FindK(a, N, k) << " is the " << k << " small number" << endl;
}
//利用查找最小的两个数 才可以将原问题进行分解
int SecondSmall(int a[], int n)
{
int min1, min2;
FindTwo(a, 0, n - 1, min1, min2);
return min2;
}
void FindTwo(int a[], int i, int j, int &fmin1, int &fmin2)
{
int lmin1, lmin2, rmin1, rmin2;
int mid;
//递归出口
if(i == j)
fmin2 = fmin1 =
[算法设计与分析]4.3.5非等分分治(一组数的第二小+一组数的第k小)
最新推荐文章于 2020-01-28 17:19:01 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)