From 35358d802bbb25b55fbaa6bc0eb085e6fb1ba7ad Mon Sep 17 00:00:00 2001 From: ArshitaKalra Date: Fri, 1 Oct 2021 02:39:53 +0530 Subject: [PATCH] stack --- C/stack.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 C/stack.c diff --git a/C/stack.c b/C/stack.c new file mode 100644 index 0000000..10fe1b0 --- /dev/null +++ b/C/stack.c @@ -0,0 +1,54 @@ +#define MAXSIZE 100 +struct stacks{ + int st[100]; + int top; +}; +typedef struct stacks stack; +void create(stack *s) +{ + s->top=-1; +} +void push(stack *s,int e) +{ + if(s->top==100-1) + { + printf("\n overflow"); + exit(-1); + } + else{ + s->top++; + s->st[s->top]=e; + } +} +int pop(stack *s) +{ + if(s->top==-1) + { + printf("stack uunderflow\n"); + exit(-1); + } + else{ + return( s->st[s->top--]); + } + +} +int isempty(stack *s) +{ + if(s->top==-1) + return 1; + else + return 0; +} +int isfull(stack *s) +{ + if(s->top==MAXSIZE-1); +} +int main() +{ + stack A,B; + create(&A);create(&B); + push(&A,10);push(&B,20); + push(&A,30); + printf("%d %d\n",pop(&A),pop(&B)); + +}