Stack

inint

You must have seen a stack of books:

stack-of-books.gif

When you want to pick up a book from this stack, you have to pick up the book first which you had placed in the last. In other words, this can be said as "Last In First Out (LIFO)".

This is the principle of Stack data structure. It works on the principle of LIFO.

The data that is pushed at last on the stack is first to pop out. Hence, there are two operations on stack:

  1. Push: Putting a data on the stack.
  2. Pop: Taking a data out of stack.

Stacks can be implemented in C language either using Singly linked lists or arrays.

Here is a C language implementation of stack using arrays. (stack1.cpp (1.36 KB))


Copyright Satya Services - 2008