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.
Next Steps:
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Buy Computer Science Books
- Practice Programming MCQs
- Apply for C++ Internship
- Buy Programming Books
- Practice Computer Science MCQs