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
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Apply for C++ Internship
- Practice Programming MCQs
- Check C++ Books
- Practice Computer Science MCQs
- Check Computer Science Books