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

Yana

This C program implements a stack data structure with operations for pushing, popping, and displaying elements. It allows the user to specify the size of the stack and handles overflow and underflow conditions. The program continues to prompt the user for actions until they choose to exit.
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)
4 views1 page

Yana

This C program implements a stack data structure with operations for pushing, popping, and displaying elements. It allows the user to specify the size of the stack and handles overflow and underflow conditions. The program continues to prompt the user for actions until they choose to exit.
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

#include <stdio.

h>
#include <conio.h>
int main()
{
int top = -1, val, stack[5], ch = 1, n, i;
printf("enter the size of stack");
scanf("%d", &n);
printf("choice\n1.push\n2.pop\n3.display\n4.exit");
while (ch)
{
printf("\nenter the choice");
scanf("%d", &ch);
switch (ch)
{
case 1:
if (top == n - 1)
{
printf("stack is overflow");
}
else
{
printf("enter the values in stack");
scanf("%d", &val);
top = top + 1;
stack[top] = val;
}
break;
case 2:
if (top == -1)
{
printf("stack is underflow");
}
else
{
printf("delete the value:%d", val);
val = stack[top];
top = top - 1;
}
break;
case 3:
printf("display stack");
for (i = 0; i <= top; i++)

{
printf("%d", stack[i]);
}
break;
case 4:
ch = 4;
printf("exit");
}
if (ch == 4)
break;
}
return 0;
}

You might also like