Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imp Push Pop Terv #434

Open
bca072024 opened this issue Jul 12, 2024 · 0 comments
Open

Imp Push Pop Terv #434

bca072024 opened this issue Jul 12, 2024 · 0 comments

Comments

@bca072024
Copy link

Write a c program to implement of push,pop and traverse operation on stack
#include<stdio.h>
#include<conio.h>
#define stack_size 5
void push(void); void pop(void); void display(void); int Top = -1; int STACK[stack_size];
void main()
{
int choice;
while(1)
{
printf("\n\n\t\t\t\t\t M A I N - M E N U");
printf("\n\n\t\t\t\t\t 1.PUSH ");
printf("\n\n\t\t\t\t\t 2.POP ");
printf("\n\n\t\t\t\t\t 3.DISPLAY");
printf("\n\n\t\t\t\t\t 4.EXIT");
printf("\n\n\t\t\t\t\t Enter Your Choice [1-4]"); scanf("%d",&choice);
switch (choice)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("\n\n \t\t\t\t\t Invalid coice");
break;
}
}
}
void push()
{
int num;
if(Top == stack_size-1)
{
printf("\n\n \t\t\t\t\t Stack full");
}
else
{
printf("\n\n \t\t\t\t\t Enter value to push");
scanf("%d",&num);
STACK[++Top]=num;
}
}
void pop()
{
int num;
if(Top == -1)
{
printf("\n\n \t\t\t\t\t stack Under flow");
}
else
{
num=STACK[Top--];
printf("\n\n \t\t\t\t\t Deleted item=%d",num);
scanf("%d",&num);
}
}
void display()
{
int i;
system("cls");
printf("\n Elements in stack are:");
for(i=Top;i>=0;i--)
printf("%d ",STACK[i]);
getch();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant