-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.c
50 lines (48 loc) · 813 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
39
40
41
42
43
44
45
46
47
48
49
50
#include<stdlib.h>
#include"stack.h"
// Stack implementation to store number list.
void iinit(istack *s) {
*s = NULL;
}
void ipush (istack *s, number *t) {
istack temp;
temp = (inode *)malloc(sizeof(inode));
temp->a = t;
temp->p = *s;
*s = temp;
}
number *ipop(istack *s) {
number *t;
istack temp;
t = (*s)->a;
temp = *s;
*s = (*s)->p;
free(temp);
return t;
}
int iisempty (istack *s) {
return *s == NULL;
}
// Stack implementation to store character Operators.
void cinit(cstack *s) {
*s = NULL;
}
void cpush (cstack *s, char t) {
cstack temp;
temp = (cnode *)malloc(sizeof(cnode));
temp->a = t;
temp->p = (*s);
*s = temp;
}
char cpop(cstack *s) {
char t;
cstack temp;
temp = (*s);
t = (*s)->a;
*s = (*s)->p;
free(temp);
return t;
}
int cisempty (cstack *s) {
return *s == NULL;
}