The perfect place for easy learning...

Data Structures

×

Topics List

Place your ad here

Stack ADT

What is a Stack?

Stack is a linear data structure in which the insertion and deletion operations are performed at only one end. In a stack, adding and removing of elements are performed at a single position which is known as "top". That means, a new element is added at top of the stack and an element is removed from the top of the stack. In stack, the insertion and deletion operations are performed based on LIFO (Last In First Out) principle.

Stack Representation

In a stack, the insertion operation is performed using a function called "push" and deletion operation is performed using a function called "pop".

In the figure, PUSH and POP operations are performed at a top position in the stack. That means, both the insertion and deletion operations are performed at one end (i.e., at Top)

A stack data structure can be defined as follows...

Stack is a linear data structure in which the operations are performed based on LIFO principle.

Stack can also be defined as

"A Collection of similar data items in which both insertion and deletion operations are performed based on LIFO principle".

Example

If we want to create a stack by inserting 10,45,12,16,35 and 50. Then 10 becomes the bottom-most element and 50 is the topmost element. The last inserted element 50 is at Top of the stack as shown in the image below...

Stack ADT Example

Operations on a Stack

The following operations are performed on the stack...

  1. Push (To insert an element on to the stack)
  2. Pop (To delete an element from the stack)
  3. Display (To display elements of the stack)

Stack data structure can be implemented in two ways. They are as follows...

  1. Using Array
  2. Using Linked List

When a stack is implemented using an array, that stack can organize an only limited number of elements. When a stack is implemented using a linked list, that stack can organize an unlimited number of elements.

Place your ad here
Place your ad here