STACK implementation (ARRAY)
By : Himanshu Tiwari
#include<stdio.h>
int stack[100],choice,top,x,n,i;
void push(){
if(top>=n-1){
printf("STACK OVERFLOW \n");
}
else{
printf("enter value to be pushed : ");
scanf("%d",&x);
top++;
stack[top]=x;
}
}
void pop(){
if(top<=-1){
printf("STACK is UNDERFLOW \n");
}
else{
printf("%d is popped from STACK \n",stack[top]);
top--;
}
}
void display(){
if(top>=0){
for(i=top; i>=0; i--){
printf("%d\n",stack[i]);
}
}
else{
printf("STACK is EMPTY\n");
}
}
int main(){
top=-1;
printf("Enter the size of the stack : ");
scanf("%d",&n);
do{
printf(" 1. push\n 2. pop\n 3. display\n 4. exit\n");
printf("enter the choice : ");
scanf("%d",&choice);
switch(choice){
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: printf("EXIT Point .\n");
break;
default : printf("choose correct option");
break;
}
}while(choice!=4);
return 0;
}

.png)
Comments
Post a Comment