top [C++ Reference]
Keywords: stl,priority_queue,top
Date: 2009-10-09T05:31:59-0700

[[top]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## top

Syntax:

        #include <queue>
        const TYPE& top() const;

The function top() returns a reference to the top element of the priority queue. The top element is greater or at least as great as any other element in the priority queue.

For example, the following code removes all of the elements from a priority queue and uses top() to display them. Note that the elements are displayed in descending order, because top() returns the largest element in the queue:

         while( !s.empty() ) {
           cout << s.top() << " ";
           s.pop();
         }

Related Topics: pop

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •