Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by Pawan ( 7 years ago )
#include<stdio.h>
int stack[5], n = 5, top = -1, option, loop = 1;
void push();
void display();
int main(){
while(loop){
printf("\n\n-----------------\n1. Push\n2. Pop\n3. Display Stack\n4. Exit\n-----------------\n");
printf("Enter option: ");
scanf("%d", &option);
printf("-----------------");
switch(option){
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
loop = 0;
break;
default:
printf("\n\nInvalid option.");
break;
}
}
}
void push(){
int x;
if(top >= n - 1)
printf("\n\nSTACK is OVERFLOW");
else{
printf("\n\nEnter a value to be pushed: ");
scanf("%d", &x);
top++;
stack[top] = x;
printf("PUSHED!!");
}
}
void pop(){
int x;
if(top <= -1){
printf("\n\nSTACK is UNDERFLOW");
}
else{
printf("\n\nPOPPED!!");
printf("\n\nThe popped element is %d", stack[top]);
top--;
}
}
void display(){
int i;
printf("\n\nSTACK: [");
for(i = top; i > -1; i--){
printf("%d", stack[i]);
if(i != 0)
printf(", ");
}
printf("]");
}
Revise this Paste