-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathst.c
60 lines (45 loc) · 864 Bytes
/
st.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
51
52
53
54
55
56
57
58
59
60
#define token_t unsigned char
struct stack
{
struct stack *prev;
void * value;
};
void push( struct stack ** s, void * val, char size );
char isempty( struct stack * s );
void * pop( struct stack ** s, char size );
token_t peek( struct stack * s );
#ifdef IMPLEMENT
#include <stdlib.h>
#include <string.h>
char isempty( struct stack * s )
{
return !s;
}
void push( struct stack ** s, void * val, char size )
{
struct stack * p=malloc(sizeof(struct stack));
p->prev=*s;
p->value=malloc(size);
memcpy( p->value, val, size );
*s=p;
return;
}
void * pop( struct stack ** s, char size )
{
struct stack * p;
void * res;
res=malloc(size);
memcpy( res, (*s)->value, size );
p=(*s)->prev;
free((*s)->value);
free(*s);
*s=p;
return res;
}
token_t peek( struct stack * s )
{
token_t res;
memcpy( &res, s->value, 1 );
return res;
}
#endif