Cycling through a queue. : Queue « Data Structure « C++






Cycling through a queue.

Cycling through a queue.

#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main()
{
  queue<string> queueObject;
  
  queueObject.push("one");
  queueObject.push("two");
  queueObject.push("three");

  cout << "Contents of queue: ";
  for(int i = 0; i < queueObject.size(); i++) {
    cout << queueObject.front() << " ";

    // remove front and push on back
    queueObject.push( queueObject.front() ); 
    queueObject.pop();
  }
  cout << endl;

  cout << "Now, remove elements:\n";
  while( !queueObject.empty() ) {
    cout << "Popping ";
    cout << queueObject.front() << endl;
    queueObject.pop();
  }

  return 0;
}

           
       








Related examples in the same category

1.Queue: push and popQueue: push and pop
2.Demonstrate the queue class: push, front, empty and popDemonstrate the queue class: push, front, empty and pop
3.Define our own Queue classDefine our own Queue class
4.Define a queueDefine a queue
5.Your own Queue classYour own Queue class