Sunday, January 8, 2012

Stack




Stacks are a type of container adaptor, specifically designed to operate in a LIFO context (last-in first-out), where elements are inserted and extracted only from the end of the container.

stacks 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/popped from the "back" of the specific container, which is known as the top of the stack.

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

back()
push_back()
pop_back()
Running Codes
#include
#include
using namespace std;



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

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

int size=s.size();
for(int i=0;ihttp://www.cplusplus.com/reference/stl/stack/



No comments:

Post a Comment