C++ Library –


C++ Library – <queue>


”;


Introduction to queue

Queue is a data structure designed to operate in FIFO (First in First out) context. In queue elements are inserted from rear end and get removed from front end.

Queue class is container adapter. Container is an objects that hold data of same type. Queue can be created from different sequence containers. Container adapters do not support iterators therefore we cannot use them for data manipulation. However they support push() and pop() member functions for data insertion and deletion respectively.

Definition

Below is definition of std::queuer from <queue> header file

template <class T, class Container = deque<T> > class queue;

Parameters

  • T − Type of the element contained.

    T may be substituted by any other data type including user-defined type.

  • Container − Type of the underlying container object.

Member types

Following member types can be used as parameters or return type by member functions.

Sr.No. Member types Definition
1 value_type T (First parameter of the template)
2 container_type Second parameter of the template
3 size_type size_t
4 reference value_type&
5 const_reference const value_type&
6 difference_type ptrdiff_t

Functions from <queue>

Below is list of all methods from <queue> header.

Constructors

Sr.No. Method & Description
1 queue::queue

Constructs an empty queue object, with zero elements.

Destructor

Sr.No. Method & Description
1 queue::~queue

Destroys queue by deallocating container memory.

Member functions

Sr.No. Method & Description
1 queue::back

Returns a reference to the last element of queue.

2 queue::emplace

Constructs and inserts new element at the end of queue.

3 queue::empty

Tests whether queue is empty or not.

4 queue::front

Returns a reference to the first element of the queue.

5 queue::operator=

Assigns new contents to the queue by replacing old ones.

6 queue::pop

Removes front element of the queue.

7 queue::push

Inserts new element at the end of queue.

8 queue::size

Returns the total number of elements present in the queue.

9 queue::swap

Exchanges the contents of queue with contents of another queue.

Non-member overloaded functions

Sr.No. Method & Description
1 operator==

Tests whether two queues are equal or not.

2 operator!=

Tests whether two queues are equal or not.

3 operator<

Tests whether first queue is less than other or not.

4 operator<=

Tests whether first queue is less than or equal to other or not.

5 operator>

Tests whether first queue is greater than other or not.

6 operator>=

Tests whether first queue is greater than or equal to other or not.

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *