min heap
// range heap example
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
bool cmp( int x, int y)
{
return x > y;
}
int main () {
int myints[] = {10,20,30,5,15};
vector<int> v(myints,myints+5);
vector<int>::iterator it;
make_heap (v.begin(),v.end(),cmp);
cout << "initial min heap : " << v.front() << endl;
pop_heap (v.begin(),v.end(),cmp); //pop_heap并没有删除此元素,只是放到对末
cout << "min heap after pop : " << v.front() << endl;
v.push_back(99); push_heap (v.begin(),v.end(),cmp);
cout << "min heap after push: " << v.front() << endl;
//sort_heap (v.begin(),v.end());
//cout << "final sorted range :";
//for (unsigned i=0; i<v.size(); i++) cout << " " << v[i];
//cout << endl;
return 0;
}
posted on 2011-07-29 16:29 more think, more gains 阅读(196) 评论(0) 编辑 收藏 举报