#include <stdlib.h>
#include "stack.h"
struct stack_node *init(int value) {
struct stack_node *node = (struct stack_node *)malloc(sizeof(struct stack_node));
if (node != NULL) {
node->value = value;
node->next = NULL;
}
return node;
}
struct stack_node *push(struct stack_node *root, int value) {
struct stack_node *new_node = init(value);
if (new_node != NULL) {
new_node->next = root;
}
return new_node;
}
struct stack_node *pop(struct stack_node *root) {
struct stack_node *new_root = NULL;
if (root != NULL) {
new_root = root->next;
free(root);
}
return new_root;
}
void destroy(struct stack_node *root) {
struct stack_node *current = root;
struct stack_node *next_node;
while (current != NULL) {
next_node = current->next;
free(current);
current = next_node;
}
}