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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy