aboutsummaryrefslogtreecommitdiffstats
path: root/src/misc/stack.c
diff options
context:
space:
mode:
authorGalin Simeonov <gts@volconst.com>2021-05-31 22:02:10 +0300
committerGalin Simeonov <gts@volconst.com>2021-07-15 18:00:15 +0300
commit255a49ba5a41b3854dbdfebdec75fb6229450507 (patch)
tree616ea5786cb91d03ef609d32b402941dc30e926b /src/misc/stack.c
parentf768d9bdb84e846d89aac66a4f3433a44241c298 (diff)
downloadMEGATRON-255a49ba5a41b3854dbdfebdec75fb6229450507.tar.gz
added cmake file
Diffstat (limited to 'src/misc/stack.c')
-rw-r--r--src/misc/stack.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/misc/stack.c b/src/misc/stack.c
new file mode 100644
index 0000000..272732f
--- /dev/null
+++ b/src/misc/stack.c
@@ -0,0 +1,37 @@
+#ifndef GSTACK_C
+#define GSTACK_C GSTACK_C
+#include "stack.h"
+
+
+
+void Stack_Init(Stack *stack)
+{
+ stack->size=0;
+ stack->first=NULL;
+}
+void Stack_Push(Stack *stack,void* data)
+{
+ struct Stack_Node *temp_node=malloc(sizeof(struct Stack_Node));
+ temp_node->data=data;
+ temp_node->next=stack->first;
+ stack->first=temp_node;
+ ++stack->size;
+}
+void* Stack_Pop(Stack *stack)
+{
+ void* return_value=NULL;
+ if(stack->first!=NULL)
+ {
+ struct Stack_Node *temp_first=stack->first;
+ return_value=stack->first->data;
+
+ --stack->size;
+ stack->first=stack->first->next;
+ free(temp_first);
+ }
+
+ return return_value;
+}
+
+#endif//#ifndef GSTACK_C
+