-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack.c
More file actions
36 lines (30 loc) · 720 Bytes
/
stack.c
File metadata and controls
36 lines (30 loc) · 720 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
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
void stack_init(linear_stack_t *s) {
s->storing = 0;
s->size = 0;
s->storage = NULL;
}
void stack_realloc(linear_stack_t *s, unsigned int size) {
s->storage = realloc(s->storage, size * sizeof(void *));
if (size && s->storage == NULL) {
fprintf(stderr, "Allocation error!\n");
exit(2);
}
s->size = size;
}
/*inline int stack_push(linear_stack_t *s, uint64_t p) {
if(s->storing > s->size-1) {
stack_realloc(s, s->size * 2);
}
*(s->storage + s->storing++) = p;
return 0;
}
inline uint64_t stack_pop(linear_stack_t *s) {
uint64_t ret;
if (s->storing == 0) return NULL;
ret = *(s->storage + (s->storing-1));
s->storing--;
return ret;
}*/