Some fixes + improvements (Vector) + code reformatting
[cgds.git] / src / Stack.c
... / ...
CommitLineData
1/**
2 * @file Stack.c
3 */
4
5#include "cgds/Stack.h"
6
7void _stack_init(Stack* stack, size_t dataSize)
8{
9 stack->dataSize = dataSize;
10 _vector_init(stack->array, dataSize);
11}
12
13Stack* _stack_new(size_t dataSize)
14{
15 Stack* stack = (Stack*) safe_malloc(sizeof (Stack));
16 stack->array = _vector_new(dataSize);
17 _stack_init(stack, dataSize);
18 return stack;
19}
20
21Stack* stack_copy(Stack* stack)
22{
23 Stack* stackCopy = (Stack*) safe_malloc(sizeof (Stack));
24 stackCopy->dataSize = stack->dataSize;
25 Vector* arrayCopy = vector_copy(stack->array);
26 stackCopy->array = arrayCopy;
27 return stackCopy;
28}
29
30bool stack_empty(Stack* stack)
31{
32 return vector_empty(stack->array);
33}
34
35UInt stack_size(Stack* stack)
36{
37 return vector_size(stack->array);
38}
39
40void _stack_push(Stack* stack, void* data)
41{
42 _vector_push(stack->array, data);
43}
44
45void* _stack_top(Stack* stack)
46{
47 return _vector_get(stack->array, vector_size(stack->array)-1);
48}
49
50void stack_pop(Stack* stack)
51{
52 vector_pop(stack->array);
53}
54
55void stack_clear(Stack* stack)
56{
57 vector_clear(stack->array);
58}
59
60void stack_destroy(Stack* stack)
61{
62 vector_destroy(stack->array);
63 safe_free(stack);
64}