What is Stack? what is stack in data structure ?


 

 Stack:

A stack is a linear data structure  in which an element is inserted or deleted only at one end called the top end of the stack i.e. the elements are removed from a stack in the reverse order of that in which they were inserted into the stack.

 

A stack follows the principle of last-in-first-out (LIFO) system. According to the stack terminology, PUSH and POP are two terms used to insert and delete operations.


Figure 2.1. Stack


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

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

 

 Array Representation of Stack:

A stack may be represented by means of a one-way list or a linear array. Unless, otherwise stated, each of the stacks will be maintained by a linear array STACK; a variable TOP contains the location of the top element of the stack. A variable N gives the maximum number elements that can be held by the stack. The condition where TOP is NULL, indicate that the stack is empty. The condition where TOP is N, will indicate that the stack is full.

 

 Different Implementation of Stack:

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

1. Using Array

2. Using Linked List

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


Post a Comment

Thankyou

Previous Post Next Post