forked from codehouseindia/Everything
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate stack
More file actions
62 lines (54 loc) · 992 Bytes
/
create stack
File metadata and controls
62 lines (54 loc) · 992 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
53
54
55
56
57
58
59
60
61
62
# https://www.facebook.com/aniketraj.superior/posts/1076499482805501
# subscribed by code house
#include <stdio.h>
#include <stdlib.h>
struct stack
{
int size;
int top;
int *arr;
};
int isEmpty(struct stack *ptr)
{
if (ptr->top == -1)
{
return 1;
}
else
{
return 0;
}
}
int isFull(struct stack *ptr)
{
if (ptr->top == ptr->size - 1)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
// struct stack s;
// s.size = 80;
// s.top = -1;
// s.arr = (int *) malloc(s.size * sizeof(int));
struct stack *s=(struct stack *)malloc(sizeof(struct stack));
s->size = 80;
s->top = -1;
s->arr = (int *)malloc(s->size * sizeof(int));
// Pushing an element manually
// s->arr[0] = 7;
// s->top++;
// Check if stack is empty
if(isEmpty(s)){
printf("The stack is empty");
}
else{
printf("The stack is not empty");
}
return 0;
}