#include <inttypes.h>
Go to the source code of this file.
Data Structures | |
struct | struct_linked_list_node_t |
A basic implementation of a linked list node. More... | |
struct | struct_linked_list_t |
A basic implementation of a linked list. More... | |
Defines | |
#define | _TIFA_LINKED_LIST_H_ |
Typedefs | |
typedef struct struct_linked_list_t | linked_list_t |
Equivalent to struct struct_linked_list_t . | |
typedef struct struct_linked_list_node_t | linked_list_node_t |
Equivalent to struct struct_linked_list_node_t . | |
Functions | |
void | init_linked_list (linked_list_t *const list, int(*cmp_func)(const void *const data_a, const void *const data_b)) |
Initializes a linked_list_t . | |
void | clear_linked_list (linked_list_t *const list) |
Clears a linked_list_t . | |
void | append_to_linked_list (linked_list_t *const list, void *const data) |
Appends a node in a linked_list_t . | |
void | prepend_to_linked_list (linked_list_t *const list, void *const data) |
Prepends a node in a linked_list_t . | |
void * | pop_linked_list (linked_list_t *const list) |
Deletes the last node of a linked_list_t . | |
void * | push_linked_list (linked_list_t *const list) |
Deletes the first node of a linked_list_t . | |
void | insert_in_linked_list (linked_list_t *const list, void *const data) |
Inserts a node in a linked_list_t . | |
linked_list_node_t * | get_node_in_linked_list (linked_list_t *const list, void *const data) |
Gets a node in a linked_list_t . | |
linked_list_node_t * | remove_from_linked_list (linked_list_t *const list, void *const data) |
Gets a node in a linked_list_t and removes it from the list. | |
void | remove_node_from_linked_list (linked_list_t *const list, linked_list_node_t *const node) |
Removes a given node from a linked_list_t . | |
void | delete_in_linked_list (linked_list_t *const list, void *const data) |
Finds and deletes a node from a linked_list_t . |
Definition in file linked_list.h.
#define _TIFA_LINKED_LIST_H_ |
Standard include guard.
Definition at line 35 of file linked_list.h.
void append_to_linked_list | ( | linked_list_t *const | list, | |
void *const | data | |||
) |
Appends a node in a linked_list_t
.
Appends a node (whose data is given by the pointer data
) in the linked list list
.
[in] | list | A pointer to the linked_list_t . |
[in] | data | A pointer to the new node's data. |
void clear_linked_list | ( | linked_list_t *const | list | ) |
Clears a linked_list_t
.
Clears a linked list list
by freeing its nodes.
data
field is freed. However, if data
is a pointer to a structure containing some other pointers, all the memory may not be freed.[in] | list | A pointer to the linked_list_t to clear. |
void delete_in_linked_list | ( | linked_list_t *const | list, | |
void *const | data | |||
) |
Finds and deletes a node from a linked_list_t
.
Deletes the node whose data is given by the pointer data
from the linked list list
. If the node is not found, the linked list is left unchanged.
data
field is freed. However, if data
is a pointer to a structure containing some other pointers, all the memory may not be freed.[in] | list | A pointer to the linked_list_t . |
[in] | data | A pointer to the data of the node to delete. |
linked_list_node_t* get_node_in_linked_list | ( | linked_list_t *const | list, | |
void *const | data | |||
) |
Gets a node in a linked_list_t
.
Returns a pointer to a node (whose data is given by the pointer data
) from the linked list list
.
[in] | list | A pointer to the linked_list_t . |
[in] | data | A pointer to the seeked node data. |
data
, if such a node exists. NULL if no matching node is found in the linked list.
void init_linked_list | ( | linked_list_t *const | list, | |
int(*)(const void *const data_a, const void *const data_b) | cmp_func | |||
) |
Initializes a linked_list_t
.
Initializes a linked list list
:
head
to NULL
. tail
to NULL
. cmp_func
to the cmp_func
argument. length
to 0.[in] | list | A pointer to the linked_list_t to initialize. |
[in] | cmp_func | A pointer to the comparison function. |
void insert_in_linked_list | ( | linked_list_t *const | list, | |
void *const | data | |||
) |
Inserts a node in a linked_list_t
.
Inserts a node (whose data is given by the pointer data
) in the linked list list
, so that all the previous nodes have data
fields pointing to datas less than the new node's data.
[in] | list | A pointer to the linked_list_t . |
[in] | data | A pointer to the new node's data. |
void* pop_linked_list | ( | linked_list_t *const | list | ) |
Deletes the last node of a linked_list_t
.
Returns the data of the last node of the linked list list
and deletes this node, similar to Perl's pop function.
[in] | list | A pointer to the linked_list_t . |
void prepend_to_linked_list | ( | linked_list_t *const | list, | |
void *const | data | |||
) |
Prepends a node in a linked_list_t
.
Prepends a node (whose data is given by the pointer data
) in the linked list list
.
[in] | list | A pointer to the linked_list_t . |
[in] | data | A pointer to the new node's data. |
void* push_linked_list | ( | linked_list_t *const | list | ) |
Deletes the first node of a linked_list_t
.
Returns the data of the first node of the linked list list
and deletes this node, similar to Perl's push function.
[in] | list | A pointer to the linked_list_t . |
linked_list_node_t* remove_from_linked_list | ( | linked_list_t *const | list, | |
void *const | data | |||
) |
Gets a node in a linked_list_t
and removes it from the list.
Returns a pointer to a node (whose data is given by the pointer data
) from the linked list list
and removes this node from the list.
[in] | list | A pointer to the linked_list_t . |
[in] | data | A pointer to the seeked node data. |
data
, if such a node exists. NULL if no matching node is found in the linked list.
void remove_node_from_linked_list | ( | linked_list_t *const | list, | |
linked_list_node_t *const | node | |||
) |
Removes a given node from a linked_list_t
.
Removes the node whose data is given by the pointer data
from the linked list list
. If the node is not found, the linked list is left unchanged.
[in] | list | A pointer to the linked_list_t . |
[in] | node | A pointer to the node to remove from the list. |