12 February, 2015

Data Structures: Implementation of Stacks using linked lists in C++

Implementation of Stack Data Structure

 

Pre-requisites : 
  • A working knowledge of pointer operations 
  • Some idea about what a stack, linked list etc is
Stack is nothing but a list with the restriction that the operations can be performed only from one side, called "top".

Whatever the operation may be(insertion or deletion) has to be performed at the top.

You can visualize it as something like this.




A more real life example would be this






You can remove a plate from top and add only at the top. Or to be more precise it follows the LIFO(Last in first out) rule

Some operations which we can be performed are

  1. push
  2. pop
  3. top(gives the element at the top of the stack) 
  4. IsEmpty ( tells whether the stack is empty or not ! ) 
Here is simple C++ implementation of Stacks using Linked Lists.


Something relevant.
Hope it helped. Stay tuned for more!

No comments:

Post a Comment