C++ Queue
A queue follows first in first out(FIFO).
A push() function helps to insertion of a new element at the rear end of the queue.
A pop() function helps to the element in the queue is deleted from the front end.
Syntax:
template<class T, class Container = deque<T> > class queue;
Example:
#include <iostream> #include <queue> using namespace std; int main() { queue<int> q; int result=0; for (int j=1; j<=5; j++) q.push(j); while (!q.empty () ) { result += q.front (); q.pop(); } cout << "Result is: " << result; return 0; }
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.