/**
@file queue.cc
@author Mitch Richling <http://www.mitchr.me/>
@Copyright Copyright 2000 by Mitch Richling. All rights reserved.
@brief Example of how to use QUEUEs in the STL specified by C++ 98 .@EOL
@Keywords Standard C++ I/O character string iostream STL queue template
@Std C++98
This program is an example of how use the queue template
in the STL of C++ 98. The queue template an adapter
that will transform any conainer supporting front(),
back(), push_back(), and pop_front() into a FIFO stack
supporting front(), back(), push(), and pop(). Note
that queues support empty() and size() too.
*/
#include <queue> /* STL queue C++ */
#include <iostream> /* C++ iostream C++ */
int main() {
std::queue<int> myQueue;
for(int i=0;i<10;i++) {
myQueue.push(i);
}
std::cout << "First: " << myQueue.front() << std::endl;
std::cout << "Last: " << myQueue.back() << std::endl;
std::cout << "Size: " << myQueue.size() << std::endl;
/* We can traverse, and empty, the whole thing like this: */
std::cout << "All the elements of the queue:" << std::endl;
for(int i=0; myQueue.size()>0; i++) {
std::cout << i << ": " << myQueue.front() << std::endl;
myQueue.pop();
}
}
Generated by GNU Enscript 1.6.5.2.