Skip to main content

Write a data structure program to make an array as stack.

Ans:-
#include<stdio.h>
#define MAX 10
int st[MAX],top=-1;
void push(int st[],int val);
int pop(int st[]);
void display(int st[]);
int main()
{
int val,option;
do
{
printf("\n *****MAIN MENU*****");
printf("\n 1. PUSH");
printf("\n 2. POP");
printf("\n 3. DISPLAY");
printf("\n 4. EXIT");
printf("\n***************");
printf("\n enter your option:");
scanf("%d",&option);
switch(option)
{
case 1:
printf("\n Enter the number to be pushed on the stack:");
scanf("%d",&val);
push(st,val);
break;
case 2:
val = pop(st);
if(val!=-1)
printf("\n The value deleted from the stack is:%d",val);
break;
case 3:
display(st);
break;
  }
}
while(option!=5);
getch();
return 0;
}
void push(int st[],int val)
{
if(top==MAX-1)
{
printf("\n STACK OVERFLOW");
}
else
{
top++;
st[top]=val;
}
}
int pop(int st[])
{
int val;
if (top==-1)
{
printf("\n STACK UNDERFLOW");
return -1;
}
else
{
val=st[top];
top--;
return val;
}
}
void display(int st[])
{
int i;
if(top==-1)
printf("\n STACK IS EMPTY");
else
{
for(i=top;i>=0;i--)
printf("\n %d",st[i]);
}
}

Comments

Popular posts from this blog

Math notes

Supremum   math Logical math Recurrence Relation  

Dairy 20/05/2025

Abhi Raat ke 11:26 ho rha hai aur mai Aaj ka pura din ka diary likhne ja rha hu. Aaj Mera MCA ka last din tha aur mere liye sbse khusi ki baat thi ki ess moment pe mere papa bhi mere sath the. Aaj unka 11::45 pm pe train hai to wo chle jaenge. Aaj Subah jagte hi papa se mile aur mera din ka suruwat hi bhut acha huaa. Mai aur Papa Nasta sath me kiye aur fir mai apne Major project external viva exam ke liye gya college waha pe sir mere se phle normally talk kiye. Jaise hi mai exam ke room me enter Kiya to Maine sir se kaha sir  maine internship applore technology se ki hai fir sir se mere se puchhe ki Delhi me kaha rhte ho aur company noida hai to noida hi shift ho jate maine kaha sir hmara Jims me June hai esliye abhi nhi shift kar paya fir unhone Jims hostel ke khane ke bare me puchha ki quality kya hai maine kaha shi hai sub and then project ke bare me sequence diagram ke bare me puchhe maine ans kiya fir sir bole ki tumhare project ke according AI kaise therapy kar skta hai to ma...

React Js interview questions