This C++ program illustrates usage of queue. The std::queue class is a container adapter that gives the programmer the functionality of a queue – specifically, a FIFO (first-in, first-out) data structure. The class template acts as a wrapper to the underlying container – only a specific set of functions is provided. The queue pushes the elements on the back of the underlying container and pops them from the front.
Here is the source code of the C++ program which illustrates usage of queue. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to illustrate usage of queue container
*/
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main() {
queue<string> q;
q.push(string("George"));
q.push(string("John"));
q.push(string("Roger"));
q.push(string("Fred"));
cout << "The queue consists of " << q.size() << " people.\n";
cout << q.front() << " is at the front of the queue.\n";
cout << q.back() << " is at the back of the queue.\n"
}
$ gcc test.cpp $ a.out The queue consists of 4 people. George John Roger Fred
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Related Posts:
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Practice Programming MCQs
- Apply for C++ Internship
- Check Computer Science Books