]>
git.datanom.net - clib.git/blob - stack.c
4 typedef struct _Stack
{
10 Stack
* s
= malloc(sizeof(Stack
));
16 void* stack_pop(Stack
* stack
) {
17 if (stack_empty(stack
))
20 void* elem
= stack
->elems
[stack
->size
];
21 stack
->elems
[stack
->size
] = NULL
;
22 stack
->elems
= realloc(stack
->elems
, stack
->size
* sizeof(void*));
27 void stack_push(Stack
* stack
, void* elem
) {
32 stack
->elems
= realloc(stack
->elems
, stack
->size
* sizeof(void*));
33 stack
->elems
[stack
->size
- 1] = elem
;
36 void* stack_peek(Stack
* stack
) {
37 if (stack_empty(stack
))
39 return stack
->elems
[stack
->size
- 1];
42 bool stack_empty(Stack
* stack
) {
43 return (stack
== NULL
|| stack
->size
== 0);
46 void** stack_clear(Stack
** stack
) {
49 void** elems
= (*stack
)->elems
;
This page took 0.075269 seconds and 6 git commands to generate.