![]() |
In C++ STL, we have a queue container that simulates the queue data structure and follows the FIFO (First In, First Out) rule. In this article, we will learn how to enqueue (insert) an element into a queue in C++. Example: Input: myQueue = {10, 20, 30}; elementToEnqueue= 40 Add an Element to a Queue in C++To enqueue an element into a std::queue in C++ STL, we can use the std::queue::push() function that inserts a new element at the end of the queue, after its current last element. C++ Program to Enqueue an Element into a QueueThe below example demonstrates how we can enqueue an element into a queue in C++. C++
Output
Elements in a Queue are: 10 20 30 40 Time Complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 15 |