Sunday, January 8, 2012

Queue(Standard Template Library)




queues are a type of container adaptor, specifically designed to operate in a FIFO context (first-in first-out), where elements are inserted into one end of the container and extracted from the other.

queues are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. Elements are pushed into the "back" of the specific container and popped from its "front".

The underlying container may be one of the standard container class template or some other specifically designed container class. The only requirement is that it supports the following operations:

front()
back()
push_back()
pop_front()




#include
#include
using namespace std;


int main()
{
queue q;
// Initial Size : 0
cout << "Initial Size : " << q.size() << endl;

for(int i=0;i<10;i++)
{
q.push(i);
}

int size=q.size();
for(int i=0;i<5; i++)
{
cout << q.front() << endl;
q.pop();

}

cout << endl;
cin.get();
return 0;
}

No comments:

Post a Comment