diff options
author | pommicket <leonardomtenenbaum@gmail.com> | 2016-02-28 13:12:20 -0500 |
---|---|---|
committer | pommicket <leonardomtenenbaum@gmail.com> | 2016-02-28 13:12:20 -0500 |
commit | cdde99ac0fdbcad1133e9482c8a6d283c7842a5b (patch) | |
tree | bb6dc0a6b60ef0fdcc610d48b3dd2c6418603ed8 /AutoVideos/src/GNULinux/Stack.h | |
parent | 487adb199603d0dd009dd626f569435eb6bcd36a (diff) |
Created AutoArt
Diffstat (limited to 'AutoVideos/src/GNULinux/Stack.h')
-rw-r--r-- | AutoVideos/src/GNULinux/Stack.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/AutoVideos/src/GNULinux/Stack.h b/AutoVideos/src/GNULinux/Stack.h new file mode 100644 index 0000000..4e190fa --- /dev/null +++ b/AutoVideos/src/GNULinux/Stack.h @@ -0,0 +1,40 @@ +typedef struct Stack +{ + matrix** array; + int index; + int capacity; +} Stack; + +Stack* createStack() +{ + Stack* p = malloc(sizeof(Stack)); + p->index = 0; + p->capacity = 0; + p->array = NULL; + return p; +} + +void resize(Stack* s, int newSize) +{ + if (newSize == 0) + newSize = 1; + matrix** oldArray = s->array; + s->array = malloc(newSize * sizeof(matrix*)); + int i; + for (i = 0; i < s->capacity; i++) + s->array[i] = oldArray[i]; + s->capacity = newSize; +} + +void push(Stack* s, matrix* value) +{ + if (s->index >= s->capacity) + resize(s, s->capacity*2); + + s->array[s->index++] = value; +} + +matrix* pop(Stack* s) +{ + return s->array[--s->index]; +} |