The C++ queue is an STL class template structure that represents a container for holding elements in a particular order. It follows the First In First Out (FIFO) sequence for data items. It is present in the header file, belonging to the Standard Template Library (STL).
Code Example:
#include #include using namespace std; int main() { queue q; //Declaring queue of integer datatype
for(int i=1;i<=5;i++) q.push(i); //Inserting elements in queue
cout<<"Size of queue: "< cout<<"Elements in queue are: "; while(!q.empty()) { cout< q.pop(); //Removing the front element of queue } return 0; }
This code example creates a queue of integer datatype, inserts elements in the queue, prints the size of the queue, and then prints the elements present in the queue using the .front() function.
Package Library: Standard Template Library (STL).
C++ (Cpp) queue - 30 examples found. These are the top rated real world C++ (Cpp) examples of queue extracted from open source projects. You can rate examples to help us improve the quality of examples.