Instead of directly maintaining the controlled sequence, the container adapter implements all functions through the underlying container object stored in it.
The queue class allows you to insert elements at the end of the underlying data structure, and also allows you to insert elements from the front (first in, first out).
Include header file #include <queue> Declaration namespace using namespace Std;
Common Queue operations:
1.void push (const t& val); Inserts an element at the end of the queue (implemented by invoking the Push_back function of the underlying container)
2.void pop (); Deleting elements in front of the queue (implemented by invoking the Pop_back function of the underlying container)
3.value_type& Front (); Gets a reference to the first element in the queue (implemented by invoking the front function of the underlying container)
4.value_type& back (); Gets the last element of the queue (implemented by invoking the back function of the underlying container)
5.bool empty () const; Determines whether the queue is empty (implemented by calling the empty function of the underlying container)
6.size_type size () const; Gets the number of queue elements (implemented by invoking the size function of the underlying container)
For best performance, use the Deque class as the underlying container for the queue
such as: queue<int> values;
Values.push (1);
Values.push (2);
Values.push (3);
while (!values.empty ())
{
cout<< "Pop Value:" <<values.front () <<endl;
Values.pop ();
}
Program output:
STL Standard Library of C + + learning notes (eight) queue container adapter