C++ make_heap,push_heap,pop_heap,sort_heap(以最大的K个数为例)

找出最大的20个数


#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;


int main(){
	//freopen("C:\\in.txt","r",stdin);
	vector t(50);
	
	iota(t.begin(),t.end(),1);
	random_shuffle(t.begin(),t.end());
	for_each(t.begin(),t.end(),[](int i){cout<());
	for(auto it=t.begin()+21;it!=t.end();){
		push_heap(t.begin(),t.begin()+21,greater());
		pop_heap(t.begin(),t.begin()+21,greater());
		it=t.erase(t.begin()+20);
	}
	sort(t.begin(),t.end(),greater());
	for_each(t.begin(),t.end(),[](int i){cout<



你可能感兴趣的:(STL)