Last active
July 15, 2019 14:21
-
-
Save ryonagana/cdc10e6bb886301447fc5510aa81e622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include "include/engine/stack.h" | |
#include "include/engine/mem.h" | |
void stack_init(CB_STACK **elem, void *data) | |
{ | |
CB_STACK *n_element = NULL; | |
n_element = malloc(sizeof(CB_STACK)); | |
n_element->next = NULL; | |
n_element->prev = NULL; | |
n_element->element = data; | |
n_element->count = 0; | |
*elem = n_element; | |
} | |
void *stack_first_element(CB_STACK **stack) | |
{ | |
if( (*stack) != NULL){ | |
return (*stack)->element; | |
} | |
return NULL; | |
} | |
void stack_add_elem(CB_STACK **stack, void *e){ | |
CB_STACK *n_stack = NULL; | |
if( (*stack)->next == NULL){ | |
n_stack = malloc(sizeof(CB_STACK)); | |
stack_init(&n_stack, e); | |
(*stack)->count++; | |
(*stack)->next = n_stack; | |
(*stack) = (*stack)->next; | |
return; | |
} | |
return; | |
} | |
void *stack_next(CB_STACK **elem){ | |
if((*elem)->next == NULL ){ | |
return (*elem)->element; | |
} | |
*elem = (*elem)->next; | |
return (*elem)->element; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment