3 // Copyright (C) 2005-2013 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
23 // Permission to use, copy, modify, sell, and distribute this software
24 // is hereby granted without fee, provided that the above copyright
25 // notice appears in all copies, and that both that copyright notice
26 // and this permission notice appear in supporting documentation. None
27 // of the above authors, nor IBM Haifa Research Laboratories, make any
28 // representation about the suitability of this software for any
29 // purpose. It is provided "as is" without express or implied
33 * @file basic_priority_queue_example.cpp
34 * A basic example showing how to use priority queues.
38 * This example shows how to use priority queues. It defines a
39 * function performing a sequence of operations on
40 * a generic container. It then calls this function with some containers.
45 #include <ext/pb_ds/priority_queue.hpp>
48 using namespace __gnu_pbds
;
50 // The following function performs a sequence of operations on a
51 // priority queue object storing integers.
54 some_op_sequence(Cntnr
& r_c
)
57 assert(r_c
.size() == 0);
59 for (size_t i
= 0; i
< 10; ++i
)
61 cout
<< endl
<< "All values in the container:" << endl
;
63 typedef typename
Cntnr::const_iterator const_iterator
;
64 for (const_iterator it
= r_c
.begin(); it
!= r_c
.end(); ++it
)
67 assert(r_c
.size() == 10);
69 cout
<< "Popping all values: " << endl
;
72 cout
<< r_c
.top() << endl
;
76 assert(r_c
.size() == 0);
84 // Perform operations on a pairing-heap queue.
85 cout
<< "Pairing heap" << endl
;
86 __gnu_pbds::priority_queue
<int, less
<int>, pairing_heap_tag
> c
;
91 // Perform operations on a binomial-heap queue.
92 cout
<< "Binomial heap" << endl
;
93 __gnu_pbds::priority_queue
<int, less
<int>, binomial_heap_tag
> c
;
98 // Perform operations on a binomial-heap queue.
99 cout
<< "Redundant-counter binomial heap" << endl
;
100 __gnu_pbds::priority_queue
<int, less
<int>, rc_binomial_heap_tag
> c
;
105 // Perform operations on a binomial-heap queue.
106 cout
<< "Binary heap" << endl
;
107 __gnu_pbds::priority_queue
<int, less
<int>, binary_heap_tag
> c
;
112 // Perform operations on a thin-heap queue.
113 cout
<< "Thin heap" << endl
;
114 __gnu_pbds::priority_queue
<int, less
<int>, thin_heap_tag
> c
;