STL堆之一

#include <iostream>
#include
<algorithm>
using namespace std;
int main ()
{
int myints[] = {10,20,30,5,15},len=sizeof(myints)/sizeof(myints[0]);

make_heap(myints,myints
+len);

cout
<< "initial max heap : ";
for(int i=0;i<len;i++)
cout
<<myints[i]<<" ";cout<<endl;

pop_heap (myints,myints
+len);len--;

cout
<< "max heap after pop : " ;
for(int i=0;i<len;i++)
cout
<<myints[i]<<" ";cout<<endl;

myints[len
++]=99; push_heap (myints,myints+len);

cout
<< "max heap after push : ";
for(int i=0;i<len;i++)
cout
<<myints[i]<<" ";cout<<endl;

sort_heap (myints,myints
+len);
cout
<< "final sorted range : ";
for(int i=0;i<len;i++)
cout
<<myints[i]<<" ";cout<<endl;

return 0;
}

  

posted on 2011-07-04 10:51  sysu_mjc  阅读(133)  评论(0编辑  收藏  举报

导航