STL 4.8

Posted on 2012-02-19 09:53  无忧consume  阅读(94)  评论(0编辑  收藏  举报

// range heap example
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main () {
int ia[] = {10,20,30,5,15};
vector<int> ivec(ia,ia+5);

make_heap (ivec.begin(),ivec.end());
for (int i = 0; i < (int)ivec.size(); i++)
cout<<ivec[i]<<" ";
cout<<endl;

ivec.push_back(40);
push_heap(ivec.begin(), ivec.end());
for (int i = 0; i < (int)ivec.size(); i++)
cout<<ivec[i]<<" ";
cout<<endl;

cout<<"ivec.size() : "<<ivec.size()<<endl; //6
pop_heap(ivec.begin(), ivec.end());
cout<<"ivec.size() : "<<ivec.size()<<endl; //6
cout<<ivec.back()<<endl;
ivec.pop_back();
cout<<"ivec.size() : "<<ivec.size()<<endl; //5\

sort_heap(ivec.begin(), ivec.end());
for (int i = 0; i < (int)ivec.size(); i++)
cout<<ivec[i]<<" ";
cout<<endl;

return 0;
}

Copyright © 2024 无忧consume
Powered by .NET 9.0 on Kubernetes