-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path24_stack_using_array.c
More file actions
52 lines (44 loc) · 818 Bytes
/
Copy path24_stack_using_array.c
File metadata and controls
52 lines (44 loc) · 818 Bytes
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <stdlib.h>
typedef struct Stack{
int size;
int top;
int *arr;
} stack;
int isEmpty(stack *ptr){
if (ptr->top == -1){
return 1;
}
else{
return 0;
}
}
int isFull(stack *ptr){
if(ptr->top == ptr->size-1){
return 1;
}
else{
return 0;
}
}
int main(){
stack *s = (stack *)malloc(sizeof(stack));
s->size = 80;
s->top = -1;
s->arr = (int *)malloc(s->size * sizeof(int));
// Check if stack is empty
if(isEmpty(s)){
printf("The stack is empty\n");
}
else{
printf("The stack is not empty\n");
}
// Check if stack is full
if(isFull(s)){
printf("The stack is full\n");
}
else{
printf("The stack is not full\n");
}
return 0;
}