home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C20 / PriorityQueue4.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  708 b   |  31 lines

  1. //: C20:PriorityQueue4.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Manipulating the underlying implementation
  7. #include <iostream>
  8. #include <queue>
  9. #include <cstdlib>
  10. #include <ctime>
  11. using namespace std;
  12.  
  13. class PQI : public priority_queue<int> {
  14. public:
  15.   vector<int>& impl() { return c; }
  16. };
  17.  
  18. int main() {
  19.   PQI pqi;
  20.   srand(time(0));
  21.   for(int i = 0; i < 100; i++)
  22.     pqi.push(rand() % 25);
  23.   copy(pqi.impl().begin(), pqi.impl().end(),
  24.     ostream_iterator<int>(cout, " "));
  25.   cout << endl;
  26.   while(!pqi.empty()) {
  27.     cout << pqi.top() << ' ';
  28.     pqi.pop();
  29.   }
  30. } ///:~
  31.