summaryrefslogtreecommitdiff
path: root/AutoImages/src/Stack.h
diff options
context:
space:
mode:
Diffstat (limited to 'AutoImages/src/Stack.h')
-rw-r--r--AutoImages/src/Stack.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/AutoImages/src/Stack.h b/AutoImages/src/Stack.h
new file mode 100644
index 0000000..4e190fa
--- /dev/null
+++ b/AutoImages/src/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];
+}