(a) Stack after the pushing of elements 8,10,12,5,6
(b) Stack after the popping of 2 elements.
Implementation of Stack is explained below
Stacks can be implemented in the below given two ways ways:
a) Arrays is also implementation of stacks
b) Linked List is also implementation of stacks
a) Arrays:- To implement a stack we require a variable called top, that holds the index of the top element of stack and an array to hold the element of the stack.
For example:- #define MAX 100
Typedef struct
{ int top;
int elements [MAX]
} stack;
b) Linked List:- A stack represented by making use of a linked list is known as linked stack. The array based representation of stack suffers from the certain limitations.
Size of stack must be known to us in advance
Overflow condition may occur.
The linked representation allows a stack to develop to a limit of the computer's memory.
for example:- typedef struct node
{
int info;
struct node * next;
} stack;
stack * top;