5 #include "cgds/Stack.h"
7 void _stack_init(Stack
* stack
, size_t dataSize
)
9 stack
->dataSize
= dataSize
;
10 _vector_init(stack
->array
, dataSize
);
13 Stack
* _stack_new(size_t dataSize
)
15 Stack
* stack
= (Stack
*) safe_malloc(sizeof (Stack
));
16 stack
->array
= _vector_new(dataSize
);
17 _stack_init(stack
, dataSize
);
21 Stack
* stack_copy(Stack
* stack
)
23 Stack
* stackCopy
= (Stack
*) safe_malloc(sizeof (Stack
));
24 stackCopy
->dataSize
= stack
->dataSize
;
25 Vector
* arrayCopy
= vector_copy(stack
->array
);
26 stackCopy
->array
= arrayCopy
;
30 Bool
stack_empty(Stack
* stack
)
32 return vector_empty(stack
->array
);
35 UInt
stack_size(Stack
* stack
)
37 return vector_size(stack
->array
);
40 void _stack_push(Stack
* stack
, void* data
)
42 _vector_push(stack
->array
, data
);
45 void* _stack_top(Stack
* stack
)
47 return _vector_get(stack
->array
, vector_size(stack
->array
)-1);
50 void stack_pop(Stack
* stack
)
52 vector_pop(stack
->array
);
55 void stack_clear(Stack
* stack
)
57 vector_clear(stack
->array
);
60 void stack_destroy(Stack
* stack
)
62 vector_destroy(stack
->array
);