2023-06-25 15:14:06 +02:00
|
|
|
#ifndef __LIBCPROJECT_STACK__
|
|
|
|
#define __LIBCPROJECT_STACK__
|
2023-01-05 19:28:05 +01:00
|
|
|
|
2023-01-07 19:38:01 +01:00
|
|
|
#include <stdio.h>
|
2023-01-05 19:28:05 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-06-25 15:07:34 +02:00
|
|
|
#include "types.h"
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Stack structure => LIFO (Last In First Out).
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct stack {
|
|
|
|
struct stack_node *first;
|
|
|
|
size_t length;
|
|
|
|
};
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Stack node structure.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct stack_node {
|
|
|
|
void *data;
|
|
|
|
struct stack_node *next;
|
|
|
|
};
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Stack initialization.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct stack *stack_initialization();
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Push data to stack.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
void stack_push(struct stack *stack, void *data);
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Pop data from stack.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
void *stack_pop(struct stack *stack);
|
|
|
|
|
2023-08-03 23:01:19 +02:00
|
|
|
/**
|
|
|
|
* @brief Frees the stack.
|
2023-08-05 15:03:53 +02:00
|
|
|
* @since v3.0.0
|
2023-08-03 23:01:19 +02:00
|
|
|
*/
|
|
|
|
void stack_free(struct stack *stack);
|
|
|
|
|
2023-01-05 19:28:05 +01:00
|
|
|
#endif
|