diff options
Diffstat (limited to 'src/02/05/stack.c')
| -rw-r--r-- | src/02/05/stack.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/02/05/stack.c b/src/02/05/stack.c new file mode 100644 index 0000000..18a344a --- /dev/null +++ b/src/02/05/stack.c @@ -0,0 +1,29 @@ +#include "stack.h" +#include <stdlib.h> + +Node *node_init(int data) { + Node *node = malloc(sizeof(Node)); + node->next = NULL; + node->data = data; + return node; +} + +Stack *stack_init(int data) { + Stack *stack = malloc(sizeof(Stack)); + stack->head = node_init(data); + return stack; +} + +int stack_size(Stack *self) { + if (!self || !self->head) + return 0; + + int count; + Node *current = self->head; + while (current) { + ++count; + current = current->next; + } + + return count; +} |
