0% found this document useful (0 votes)
9 views1 page

Exp 18.1 DSA

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Exp 18.1 DSA

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

//Experiment 18 : WAP to implement Stack and perform Push & Pop operations.

#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);

default: // To handle entry of wrong number.


{ printf("\n\t\t!!! Invalid Operation !!!");
break;
}
}
}
}

You might also like