2023-06-25 15:14:06 +02:00
|
|
|
#ifndef __LIBCPROJECT_LINKED_LIST__
|
|
|
|
#define __LIBCPROJECT_LINKED_LIST__
|
2023-01-05 19:28:05 +01:00
|
|
|
|
2023-01-07 19:38:01 +01:00
|
|
|
#include <stdbool.h>
|
2023-01-05 19:28:05 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-01-07 19:38:01 +01:00
|
|
|
#include "stack.h"
|
2023-06-25 15:07:34 +02:00
|
|
|
#include "types.h"
|
2023-01-07 19:38:01 +01:00
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Linked list data structure.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct linked_list {
|
|
|
|
struct linked_list_node *head;
|
|
|
|
|
|
|
|
size_t length;
|
|
|
|
};
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Linked list node data structure.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct linked_list_node {
|
|
|
|
void *data;
|
|
|
|
struct linked_list_node *next;
|
|
|
|
};
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Linked list initialization.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct linked_list *linked_list_initialization();
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Add a new node in the head of the linked list.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct linked_list_node *linked_list_add_in_head(struct linked_list *list, void *new_value);
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Delete node in the head of the linked list.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
void linked_list_delete_in_head(struct linked_list *list);
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Add a new node in the tail of the linked list.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct linked_list_node *linked_list_add_after_last(struct linked_list *list, void *new_data);
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Reverse the linked list by creating a new one.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
struct linked_list *linked_list_reverse(struct linked_list *list);
|
|
|
|
|
2023-06-24 21:06:45 +02:00
|
|
|
/**
|
|
|
|
* @brief Reverse the linked list by mutating it.
|
|
|
|
* @since v1.0.0
|
|
|
|
*/
|
2023-01-05 19:28:05 +01:00
|
|
|
void linked_list_reverse_mutate(struct linked_list *list);
|
|
|
|
|
|
|
|
#endif
|