2021-10-12 22:48:23 +02:00
|
|
|
#ifndef __STACK__
|
|
|
|
#define __STACK__
|
|
|
|
|
2023-08-10 11:13:06 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
2021-10-12 22:48:23 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-08-10 11:13:06 +02:00
|
|
|
/**
|
|
|
|
* @brief Stack structure => LIFO (Last In First Out).
|
|
|
|
*/
|
|
|
|
struct stack {
|
|
|
|
struct stack_node *first;
|
2021-10-12 22:48:23 +02:00
|
|
|
size_t length;
|
|
|
|
};
|
|
|
|
|
2023-08-10 11:13:06 +02:00
|
|
|
/**
|
|
|
|
* @brief Stack node structure.
|
|
|
|
*/
|
|
|
|
struct stack_node {
|
2021-10-12 22:48:23 +02:00
|
|
|
void *data;
|
2023-08-10 11:13:06 +02:00
|
|
|
struct stack_node *next;
|
2021-10-12 22:48:23 +02:00
|
|
|
};
|
|
|
|
|
2023-08-10 11:13:06 +02:00
|
|
|
/**
|
|
|
|
* @brief Stack initialization.
|
|
|
|
*
|
|
|
|
* @return struct stack*
|
|
|
|
*/
|
|
|
|
struct stack *stack_initialization();
|
2021-10-12 22:48:23 +02:00
|
|
|
|
2023-08-10 11:13:06 +02:00
|
|
|
/**
|
|
|
|
* @brief Push data to stack.
|
|
|
|
*
|
|
|
|
* @param stack
|
|
|
|
* @param data
|
|
|
|
*/
|
|
|
|
void stack_push(struct stack *stack, void *data);
|
2021-10-12 22:48:23 +02:00
|
|
|
|
2023-08-10 11:13:06 +02:00
|
|
|
/**
|
|
|
|
* @brief Pop data from stack.
|
|
|
|
*
|
|
|
|
* @param stack
|
|
|
|
* @return void*
|
|
|
|
*/
|
|
|
|
void *stack_pop(struct stack *stack);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Frees the stack.
|
|
|
|
*
|
|
|
|
* @param stack
|
|
|
|
*/
|
|
|
|
void stack_free(struct stack *stack);
|
2021-10-12 22:48:23 +02:00
|
|
|
|
|
|
|
#endif
|