forked from dimpeshmalviya/C-Language-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
57 lines (49 loc) · 859 Bytes
/
stack.c
File metadata and controls
57 lines (49 loc) · 859 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
#include<stdio.h>
#include<stdlib.h>
struct stack
{
int size;//itna hoga chip
int top; // kon chips dal re
int * arr ; // ek chips ke baad ek saja dere h
};
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) // size is 5 but index is from 0 to 4
{
return 1;
}
else
{
return 0;
}
}
int main(){
struct stack *s;
s->size = 50;
s->top = -1;
s->arr = (int *)malloc(s->size * sizeof(int));
// pushing element just now
s->arr[0] =2;
s->top++;
s->arr[1] = 3;
s->top++;
// Check if stack is empty
if (isEmpty(s))
{
printf("The stack is empty");
}
else
{
printf("The stack is not empty");
}
return 0;
}