aboutsummaryrefslogtreecommitdiff
path: root/linkedlist/stack.c
diff options
context:
space:
mode:
authorGravatar jonas <himself@jonasgunz.de> 2019-04-12 05:18:19 +0200
committerGravatar jonas <himself@jonasgunz.de> 2019-04-12 05:18:19 +0200
commit329714471c36facbbc68cfa26ebaa51938377c7e (patch)
tree9ae9ce4d28450098216b2aa0df930b45dc2f3d7b /linkedlist/stack.c
downloadstandardstuff-329714471c36facbbc68cfa26ebaa51938377c7e.tar.gz
initialÃ
Diffstat (limited to 'linkedlist/stack.c')
-rw-r--r--linkedlist/stack.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/linkedlist/stack.c b/linkedlist/stack.c
new file mode 100644
index 0000000..de77b72
--- /dev/null
+++ b/linkedlist/stack.c
@@ -0,0 +1,38 @@
+#include "stack.h"
+
+void stack_add(void* _data, struct stack** _stackpointer)
+{
+ struct stack* newsp = malloc(sizeof(*newsp));
+
+ newsp->data = _data;
+ newsp->next = *_stackpointer;
+ *_stackpointer = newsp;
+}
+
+void* stack_get(struct stack** _stackpointer)
+{
+ void* return_data;
+ struct stack* oldsp; //Old stackpointer
+
+ if(!*_stackpointer)
+ return NULL;
+
+ return_data = (*_stackpointer)->data;
+ oldsp = *_stackpointer;
+ *_stackpointer = (*_stackpointer)->next;
+ free(oldsp);
+
+ return return_data;
+}
+
+void stack_init(struct stack** _stackpointer)
+{
+ stack_flush(_stackpointer);
+ *_stackpointer = NULL;
+}
+
+void stack_flush(struct stack** _stackpointer)
+{
+ while(*_stackpointer)
+ stack_get(_stackpointer);
+}