Expt 6 (ECS) Implement Stack ADT Using Linked List
Expt 6 (ECS) Implement Stack ADT Using Linked List
_____________________________________________________________________________________
Experiment No. 6
Title Implement Stack ADT using Linked List
Name
Year/Branch
Roll No.
UIN
Rizvi College of Engineering, Mumbai
_____________________________________________________________________________________
Theory:
The major problem with the stack implemented using an array is, it works only for a fixed number of data
values. That means the amount of data must be specified at the beginning of the implementation itself. Stack
implemented using an array is not suitable, when we don't know the size of data which we are going to use.
A stack data structure can be implemented by using a linked list data structure. The stack implemented using
a linked list can work for an unlimited number of values. That means, a stack implemented using linked list
works for the variable size of data. So, there is no need to fix the size at the beginning of the
implementation. The Stack implemented using linked list can organize as many data values as we want.
In the linked list implementation of a stack, every new element is inserted as 'top' element. That means every
newly inserted element is pointed by 'top'. Whenever we want to remove an element from the stack, simply
remove the node which is pointed by 'top' by moving 'top' to its previous node in the list. The next field of
the first element must be always NULL.
Example
In the above example, the last inserted node is 99 and the first inserted node is 25. The order of
elements inserted is 25, 32,50 and 99.
● Step 4 - Implement the main method by displaying Menu with list of operations and make suitable
function calls in the main method.
Program:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct Node
{
int data;
Rizvi College of Engineering, Mumbai
_____________________________________________________________________________________
*top = NULL;
void push(int);
void pop();
void display();
void main()
{
int choice, value;
Output:
Conclusion: In conclusion, a linked list-based stack offers efficient memory use with
dynamic allocation and allows fast insertion and deletion without the need for resizing,
making it a flexible choice over array-based stacks.
Rizvi College of Engineering, Mumbai
_____________________________________________________________________________________