#include <iostream>using namespace std;//of course the same is true with fast sorting. Class Heap{public:heap () {}void Insert (int a[],int len,int N) {data = new int[n];size = n;for (int i=0;i<n;i++) {Data[i]=a [i];} int n = n/2;while (n>=0) {setval (data,n); n--;} for (int i=n;i<len;i++) {if (Data[0]>a[i]) {data[0]=a[i]; Setval (data,0);}}} void Setval (int a[],int n) {int i = N;int j = i*2+1;while (j<size) {if (j+1<size && data[j]<data[j+1]) j=j+1; if (Data[i]<data[j]) {int temp = Data[i];d ata[i] = data[j];d ata[j] = temp;} i = J;j = I*2+1;}} int Getnum () {return data[0];} ~heap () {if (data) delete []data;} Private:int *data;int size;}; int find_n_min (int a[],int n,int val) {heap hp;//I use the large heap to solve, though it is a large heap, I will insert the smaller number,//And then in this group of smaller numbers inside, according to the large heap of ascending way, Let the first subscript position Save the value I need to find. Hp. Insert (a,n,val); return HP. Getnum ();} int main () {int a[]={2,3,4,5,6,11,2,3,3,4,4,5,5,6,0,0,0};cout<<find_n_min (a,sizeof (a)/sizeof (int), 4) < <endl;return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Written question: The number of the first n Large (small) in order to find the chaos. The best way I can think of.