Pavi Ds 1 B
Pavi Ds 1 B
DATE:
AIM:
To write a c program to perform implementation of stack operations using linked list.
OBJECTIVE:
From this program, a programmer will learn how to PUSH, POP & DISPLAY operations are
implemented in a stack using linked list.
ALGORITHM:
1. Create a struct node with integer data and a pointer to the next node.
a. push()
b.pop()
c.display()
PROGRAM:
#include <stdio.h>
#include <stdlib.h>
struct node
int info;
}*top,*top1,*temp;
int count = 0;
if (top == NULL)
top->ptr = NULL;
top->info = data;
else
temp->ptr = top;
temp->info = data;
top = temp;
count++;
printf("Node is Inserted\n\n");
int pop()
top1 = top;
if (top1 == NULL)
printf("\nStack Underflow\n");
return -1;
else
top1 = top1->ptr;
free(top);
top = top1;
count--;
return popped;
void display()
top1 = top;
if (top1 == NULL)
printf("\nStack Underflow\n");
return;
printf("%d--->", top1->info);
top1 = top1->ptr;
printf("NULL\n\n");
int main()
while (1)
scanf("%d", &choice);
switch (choice)
case 1:
scanf("%d", &value);
push(value);
break;
case 2:
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("\nWrong Choice\n");
RESULT:
Thus, the c program for implementation of stack using linked list was executed and the output was
verified.
FLOW CHART: