Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
allenjiji authored Sep 5, 2019
1 parent 952ffcc commit f566828
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions stack.c
Original file line number Diff line number Diff line change
@@ -0,0 1,63 @@
#include<stdio.h>
#include<stdlib.h>
int max=100;
int arr[100];
int top=-1;

void push(int data){
if(top>max){
printf("Impossible to push!!");
return ;
}
top ;
arr[top]=data;
return;
}

void pop(){
if (top<0){
printf("Empty stack!!");
}
else{
int a=arr[top];
top--;
printf("The element poped is:%d",a);
}
}

void display(){
if (top<0)
printf("Empty stack!!");
else{
printf("The current stack is:\n");
for(int i=0;i<top 1;i ){
printf("%d\t",arr[i]);
}
}
}


void main(){
int data,op;
while(1){
printf("\n1.PUSH\n2.POP\n3.DISPLAY\n4.Exit\nSelect the operation:");
scanf("%d",&op);
if(op==1){
printf("Enter the element to be pushed:");
scanf("%d",&data);
push(data);
}
else if(op==2){
pop();
}
else if(op==3){

display();
}
else if(op==4){
exit(0);
}
else printf("INVALID OPERATION!!");

}
}

0 comments on commit f566828

Please sign in to comment.