cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : STL Containers : priority_queue : size
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
STL Containers
bitset
deque
list
map
multimap
multiset
priority_queue
queue
set
stack
vector
priority_queue
priority_queue::priorit...
member functions:
· priority_queue::empty
· priority_queue::pop
· priority_queue::push
· priority_queue::size
· priority_queue::top

-

priority_queue::size public member function
size_type size ( ) const;

Return size

Returns the number of elements in the priority_queue.

This member function effectively calls the member with the same name in the underlying container object.

Parameters

none

Return Value

The number of elements that conform the priority_queue's container content.

Member type size_type is an unsigned integral type.

Example

// priority_queue::size
#include <iostream>
#include <queue>
using namespace std;

int main ()
{
  priority_queue<int> myints;
  cout << "0. size: " << (int) myints.size() << endl;

  for (int i=0; i<5; i++) myints.push(i);
  cout << "1. size: " << (int) myints.size() << endl;

  myints.pop();
  cout << "2. size: " << (int) myints.size() << endl;

  return 0;
}

Output:

0. size: 0
1. size: 5
2. size: 4

Complexity

Constant.

See also

priority_queue::empty Test whether container is empty (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us