Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* STL queue and priority queue examples */
- #include <iostream>
- #include <queue>
- using namespace std;
- /* simple queue example */
- void functionA()
- {
- queue <int> q; //q is a queue of integers
- q.push(2); //put 2, 5, 3, 2 into the queue
- q.push(5);
- q.push(3);
- q.push(1);
- cout<<"q contains " << q.size() << " elements.\n";
- while (!q.empty()) {
- cout << q.front() << endl; //print out the first element in the queue
- q.pop(); //remove the first element of the queue
- }
- }
- /* simple priority queue example */
- void functionB()
- {
- priority_queue <int> pq; //pq is a priority queue of integers
- pq.push(2); //put 2, 5, 3, 1 into the priority queue
- pq.push(5);
- pq.push(3);
- pq.push(1);
- cout<<"pq contains " << pq.size() << " elements.\n";
- while (!pq.empty()) {
- cout << pq.top() << endl; //print out the highest priority element
- pq.pop(); //remove the highest priority element
- }
- }
- int main()
- {
- cout << "calling functionA...\n";
- functionA();
- cout << "calling functionB...\n";
- functionB();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement