forked from sarthakd999/Hacktoberfest2021-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.c
38 lines (37 loc) · 790 Bytes
/
Stack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//C program to create a stack and perform its operations.
#include <stdio.h>
int top=-1;
int stack[5];
void push(int stack[], int item) {
if(top<4){
top++; stack[top]=item;
printf("%d is pushed into the stack\n",item);
}
else
printf("Stack is FULL...\n");
}
int pop(){
if(top>-1){
int item=stack[top];
top--;
return item;
}
else{
printf("Stack is EMPTY...\n");
return 0;
}
}
void main(){
push(stack,11);
push(stack,12);
push(stack,13);
push(stack,14);
push(stack,115);
push(stack,116);
printf("%d\n",pop());
printf("%d\n",pop());
printf("%d\n",pop());
printf("%d\n",pop());
printf("%d\n",pop());
printf("%d\n",pop());
}