📄 all.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> <title>C++ Priority Queues</title> <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table> <tr> <td> <div class="body-content"> <div class="header-box"> <a href="../index.html">cppreference.com</a> > <a href= "index.html">C++ Priority Queues</a> </div> <div class="name-format"> empty </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <queue> bool empty() const;</pre> <p>The empty() function returns true if the priority queue has no elements, false otherwise.</p> <p>For example, the following code uses empty() as the stopping condition on a (C/C++ Keywords) <a href= "../keywords/while.html">while</a> loop to clear a priority queue and display its contents in reverse order:</p> <pre class="example-code"> vector<int> v; for( int i = 0; i < 5; i++ ) { v.push_back(i); } while( !v.empty() ) { cout << v.back() << endl; v.pop_back(); } </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="size.html">size</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> pop </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <queue> void pop();</pre> <p>The function pop() removes the top element of the priority queue and discards it.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="push.html">push</a><br> <a href="top.html">top</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> Priority queue constructors </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <queue> priority_queue( const Compare& cmp = Compare(), const Container& c = Container() ); priority_queue( <a href="../iterators.html">input_iterator</a> start, <a href="../iterators.html">input_iterator</a> end, const Compare& comp = Compare(), const Container& c = Container() );</pre> <p>Priority queues can be constructed with an optional compare function <em>cmp</em> and an optional container <em>c</em>. If <em>start</em> and <em>end</em> are specified, the priority queue will be constructed with the elements between <em>start</em> and <em>end</em>.</p> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> push </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <queue> void push( const <a href="../containers.html">TYPE</a>& val );</pre> <p>The function push() adds <em>val</em> to the end of the current priority queue.</p> <p>For example, the following code uses the push() function to add ten integers to the end of a queue:</p> <pre class="example-code"> queue<int> q; for( int i=0; i < 10; i++ ) q.push(i); </pre> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> size </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <queue> <strong>size_type</strong> size() const;</pre> <p>The size() function returns the number of elements in the current priority queue.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> (C++ Strings) <a href="../cppstring/capacity.html">capacity</a><br> <a href="empty.html">empty</a><br> (C++ Strings) <a href="../cppstring/length.html">length</a><br> (C++ Multimaps) <a href= "../cppmultimap/max_size.html">max_size</a><br> (C++ Strings) <a href="../cppstring/resize.html">resize</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> top </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <queue> <a href="../containers.html">TYPE</a>& top();</pre> <p>The function top() returns a reference to the top element of the priority queue.</p> <p>For example, the following code removes all of the elements from a stack and uses top() to display them:</p> <pre class="example-code"> while( !s.empty() ) { cout << s.top() << " "; s.pop(); } </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="pop.html">pop</a> </div> </div> </td> </tr> </table></body></html><hr></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -