pickzy.com

C  |  C++  |  Objective-C  |  VC++  |  Win32  |  MFC  |  Java  |  Php  |  Delphi  |  Visual Basic  |  .Net  |  Networking  |  General  |  Games  |  Jobs  |  Javascript  |  




Menu

pickSourcecode.com


        

 




 

Cpp > Programs

 

cpp basic queue examples and tutorials

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


template<class T, class C>

void ShowQueue(const queue<T, C>& aQueue);

int main()
{

//  create  a  integer  queue
queue<int> qInt;

cout << "Queue qInt created:\n";

ShowQueue(qInt);


//  push  elements  into  the  queue
for (unsigned int i = 1; i < 5; ++i)
qInt.push(i * 2);

cout << "qInt:\n";

ShowQueue(qInt);


//  modify  the  first  and  last  elements
qInt.front() = 20;

qInt.back() = 30;

cout << "The first and last elements modified:\n";

ShowQueue(qInt);


//  remove  first  element  from  the  queue
qInt.pop();

cout << "After one pop() operation\n";

ShowQueue(qInt);


return 0;

}


//
//  Display  queue  elements
//
template<class T, class C>

void ShowQueue(const queue<T, C>& aQueue)
{

cout << "size() = " << aQueue.size();

if (!aQueue.empty())
{

cout << "\tfront() = " << aQueue.front();

cout << "\tback() = " << aQueue.back();

}

cout << "\n\n";

}


 
Privacy Policy | About Us