Exp 18.1 DSA
Exp 18.1 DSA
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define MAX 10
struct stack
{ int arr[MAX];
int top;
};
void main()
{
struct stack s;
int item,choice;
s.top=-1;
printf("\n Experiment 18 : This is a Program to implement Stack & perform Push
and Pop operations.");
while(1)
{
printf("\nPress 1->Push, 2->Pop or 3->Exit");
printf("\n Choose Stack operation :");
scanf("%d",&choice);
switch(choice)
{
case 1: //Performing Push Operation.
{ if(s.top==MAX-1) //Check Overflow
printf("\n\t\t!!! Stack is full !!!");
else
{ printf("\nEnter the element to be Inserted:");
scanf("%d",&item);
s.top=s.top+1;
s.arr[s.top]=item;
}
break;
}
case 2: //Performing Pop Operation.
{ if(s.top==-1) //Check Underflow
printf("\n\t\t!!! Stack is Empty !!!");
else
{ item=s.arr[s.top];
s.top=s.top-1;
printf("\nPopped element is: %d",item);
}
break;
}
case 3: //Exit of Program
exit(0);