Created
December 6, 2018 04:21
-
-
Save krishnaprajapat/c2ded4c44f225d919edf0ded9c8587c7 to your computer and use it in GitHub Desktop.
Array representation of stack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define MAX 100; | |
int top=-1,stack[100]; | |
void push(int item,int n) | |
{ | |
if(top==n-1) | |
printf("\n stack overflow"); | |
else | |
{ | |
top=top+1; | |
stack[top]=item; | |
} | |
} | |
void pop() | |
{ | |
int temp; | |
if(top==-1) | |
printf("\n stack underflow"); | |
else | |
{ | |
temp=stack[top]; | |
top=top-1; | |
} | |
} | |
void display(int n) | |
{ | |
for(int i=0;i<=top;i++) | |
{ | |
printf("\n%d",stack[i]); | |
} | |
} | |
int main() | |
{ | |
int n,item,ch; | |
printf("\n enter size"); | |
scanf("%d",&n); | |
printf("\n1push\n2pop\n3display"); | |
while(1){ | |
printf("\n enter choice"); | |
scanf("%d",&ch); | |
switch(ch) | |
{ | |
case 1: | |
{ | |
printf("enter number"); | |
scanf("%d",&item); | |
push(item,n); | |
break; | |
} | |
case 2: | |
{ | |
pop(); | |
break; | |
} | |
case 3: | |
{ | |
display(n); | |
break; | |
} | |
default: | |
printf("\n invalid choice"); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment