0% found this document useful (0 votes)
18 views2 pages

Blank

Uploaded by

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

Blank

Uploaded by

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

#include<stdio.

h>
#include<stdlib.h>
#de ne MAX 2

int stack[MAX];
int top=-1;

void push(){
int element;
if (top==MAX-1){
printf("over ow:stack is full\n");
}
else{
printf("enter the element:");
scanf("%d",&element);
stack[++top]=element;
printf("%d added to stack\n",element);
}
}

void pop(){
if( top == -1){
printf("stack under ow:stack is empty\n");
}
else{
printf("%d deletd from the stack\n",stack[top--]);
}
}

void display(){
if( top == -1){
printf("stack is empty\n");
}
else{
printf("stack contents:\n");
for(int i=top;i>=0;i--){
printf("%d\t\t",stack[i]);
}
printf("\n");
}
}

int main(){
int choice;
while(1){
printf("enter 1 for push\n");
printf("enter 2 for pop\n");
printf("enter 3 for display\n");
printf("enter 4 for exit\n");
printf("enter your choice:");
scanf("%d", &choice);
switch(choice){
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
fi
fl
fl
break;
case 4:
printf("exiting.....\n");
exit(0);
default:
printf("please enter correcct choice\n") ;
}
}
return 0;
}

You might also like