Queue: push, pop and size : queue « Queue Stack « C++






Queue: push, pop and size

   
 


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

int main()
{

  int thedata[] = {45, 34, 56, 27, 71, 50, 62};
  queue<int, list<int> > q;  
  cout << "The queue size is now " << q.size() << endl;

  cout << "Pushing 4 elements " << endl;
  for (int i = 0; i < 4; ++i)
    q.push(thedata[i]);
  cout << "The queue size is now " << q.size() << endl;

  cout << "Popping 3 elements " << endl;
  for (int i = 0; i < 3; ++i) {
    cout << q.front() << endl;
    q.pop();
  }
  cout << "The queue size is now " << q.size() << endl;

  return 0;
}

 /* 
The queue size is now 0
Pushing 4 elements
The queue size is now 4
Popping 3 elements
45
34
56
The queue size is now 1

 */       
    
    
  








Related examples in the same category

1.queue with doubles
2.queue: push, pop, front and size
3.queue.front()
4.Queue of string: push(), empty(), front(), pop()
5.Put string into a queue