#include #include using namespace std; int main(void) { int d1[4] = {1,2,3,4}; int d2[4] = {1,3,2,4}; // Set up two vectors vector v1(d1,d1 + 4), v2(d2,d2 + 4); // Make heaps make_heap(v1.begin(),v1.end()); make_heap(v2.begin(),v2.end(),less()); // v1 = (4,x,y,z) and v2 = (4,x,y,z) // Note that x, y and z represent the remaining // values in the container (other than 4). // The definition of the heap and heap operations // does not require any particular ordering // of these values. // Copy both vectors to cout cout<< "make_heap()"<< endl; ostream_iterator out(cout," "); copy(v1.begin(),v1.end(),out); cout << endl; copy(v2.begin(),v2.end(),out); cout << endl; // Now let's pop pop_heap(v1.begin(),v1.end()); pop_heap(v2.begin(),v2.end(),less()); // v1 = (3,x,y,4) and v2 = (3,x,y,4) // Copy both vectors to cout cout<< "\npop_heap()"<< endl; copy(v1.begin(),v1.end(),out); cout << endl; copy(v2.begin(),v2.end(),out); cout << endl; // And push push_heap(v1.begin(),v1.end()); push_heap(v2.begin(),v2.end(),less()); // v1 = (4,x,y,z) and v2 = (4,x,y,z) // Copy both vectors to cout cout<< "\npush_heap()"<< endl; copy(v1.begin(),v1.end(),out); cout << endl; copy(v2.begin(),v2.end(),out); cout << endl; // Now sort those heaps sort_heap(v1.begin(),v1.end()); sort_heap(v2.end(),v2.begin(),greater()); // v1 = (1,2,3,4), v2 = (4,3,2,1) // Copy both vectors to cout cout<< "\nsort_heap()"<< endl; copy(v1.begin(),v1.end(),out); cout << endl; copy(v2.begin(),v2.end(),out); cout << endl <<"\nPress any key to exit..."; while ( !cin.get() ) ; return 0; }