STL 堆排序

#include<algorithm>



#include <functional>



using namespace std;



STL中堆的使用:



       vector<int> a;



       //建堆,建好后第一个元素最大(小)



       make_heap(a.begin(),a.end(), less<int>() );





       //取最大值



       x=a.front();



       pop_heap(a.begin(),a.end(), less<int>() );



       a.pop_back(); // 删除最后一个数据





       //插入元素



       a.push_back(x);



       push_heap(a.begin(),a.end(),cmp);





       //堆排序



       sort_heap(a.begin(),a.end(),cmp);

  

你可能感兴趣的:(STL)