C++ Queue Library - empty() Function



Description

The C++ function std::priority_queue::empty() tests whether pritority_queue is empty or not. Priority_queue of zero size is considered as empty queue.

Declaration

Following is the declaration for std::priority_queue::empty() function form std::queue header.

C++98

bool empty() const;

Parameters

None

Return value

Returns true if priority_queue is empty otherwise false.

Exceptions

This member function never throws exception.

Time complexity

Constant i.e. O(1)

Example

The following example shows the usage of std::priority_queue::empty() function.

#include <iostream>
#include <queue>

using namespace std;

int main(void) {
   priority_queue<int> q;

   if (q.empty())
      cout << "Priority_queue is empty." << endl;

   q.emplace(1);

   if (!q.empty())
      cout << "Priority_queue is not empty." << endl;

   return 0;
}

Let us compile and run the above program, this will produce the following result −

Priority_queue is empty.
Priority_queue is not empty.
queue.htm
Advertisements