Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
priority_queue.cpp
Go to the documentation of this file.
1
29#include <deque> // for deque
30#include <iostream> // for cout, endl
31#include <queue> // for priority_queue
32#include <string> // for string
33#include <vector> // for vector
34
35#include <examples.h>
36
37
38int main ()
39{
40 // Make a priority queue of int using a vector container.
41 std::priority_queue<int,
42 std::vector<int, std::allocator<int> >,
43 std::less<int> > pq;
44 // Push a couple of values.
45 pq.push (1);
46 pq.push (2);
47
48 // Pop a couple of values and examine the ends.
49 std::cout << pq.top () << std::endl;
50 pq.pop ();
51 std::cout << pq.top () << std::endl;
52 pq.pop ();
53
54 // Make a priority queue of strings.
55 std::priority_queue<std::string,
56 std::deque<std::string, std::allocator<std::string> >,
57 std::less<std::string> > pqs;
58
59 // Push on a few strings then pop them back off.
60 for (int i = 0; i < 10; i++) {
61 pqs.push (std::string (i + 1, 'a'));
62 std::cout << pqs.top () << std::endl;
63 }
64
65 for (int j = 0; j < 10; j++) {
66 std::cout << pqs.top () << std::endl;
67 pqs.pop ();
68 }
69
70 // Make a priority queue of strings using greater.
71 std::priority_queue<std::string,
72 std::deque<std::string,
73 std::allocator<std::string> >,
74 std::greater<std::string> > pgqs;
75
76 // Push on a few strings then pop them back off.
77 for (int k = 0; k < 10; k++) {
78 pgqs.push (std::string (k + 1, 'a'));
79 std::cout << pgqs.top () << std::endl;
80 }
81
82 for (int m = 0; m < 10; m++) {
83 std::cout << pgqs.top () << std::endl;
84 pgqs.pop ();
85 }
86
87 return 0;
88}
#define m
Definition 17.names.cpp:129
#define i
Definition 17.names.cpp:126
#define k
Definition 17.names.cpp:128
#define j
Definition 17.names.cpp:127
int main()