110 lines
2.6 KiB
C
110 lines
2.6 KiB
C
#ifndef LISTS_H
|
|
#define LISTS_H
|
|
|
|
#include <stddef.h>
|
|
|
|
struct list
|
|
{
|
|
void *data;
|
|
struct list *next;
|
|
};
|
|
|
|
/*
|
|
** @brief Insert a node containing `value` at the beginning of the list.
|
|
** @return `NULL` if an error occured.
|
|
*/
|
|
struct list *list_prepend(struct list *list, void *value);
|
|
|
|
/*
|
|
** Return the lenght of the list.
|
|
** Return `0` if the list is empty.
|
|
*/
|
|
size_t list_length(struct list *list);
|
|
|
|
/*
|
|
** Display the list contents on `stdout`.
|
|
** Nothing is displayed if the list is empty.
|
|
*/
|
|
void list_print(struct list *list);
|
|
|
|
/*
|
|
** Release the memory used by the list.
|
|
** Does nothing if `list` is `NULL`.
|
|
*/
|
|
void list_destroy(struct list *list);
|
|
|
|
/*
|
|
** Release the memory used by the list and its content
|
|
** Does nothing if `list` is `NULL`.
|
|
*/
|
|
void list_deep_destroy(struct list *l);
|
|
|
|
/*
|
|
** Append a node containing `value` at the end of the list.
|
|
** Return `NULL` if an error occured.
|
|
*/
|
|
// START PROTO list_append
|
|
struct list *list_append(struct list *list, void *value);
|
|
// END PROTO list_append
|
|
|
|
/*
|
|
** Insert a node containing `value` at the index `index` in the list.
|
|
** If the index is greater than the length of the list, the behaviour is the
|
|
** same as `list_append`.
|
|
** Return `NULL` if an error occured.
|
|
*/
|
|
// START PROTO list_insert
|
|
struct list *list_insert(struct list *list, void *value, size_t index);
|
|
// END PROTO list_insert
|
|
|
|
/*
|
|
** Remove the element at the index `index`.
|
|
** Return `NULL` if an error occured.
|
|
*/
|
|
// START PROTO list_remove
|
|
struct list *list_remove(struct list *list, size_t index);
|
|
// END PROTO list_remove
|
|
|
|
/*
|
|
** Return the position of the first node containing `value`.
|
|
** Return `-1` if nothing is found.
|
|
*/
|
|
// START PROTO list_find
|
|
int list_find(struct list *list, void *value);
|
|
// END PROTO list_find
|
|
|
|
/*
|
|
** Concatenate the list `list2` at the end of the list `list`.
|
|
** Return `list2` if `list` is `NULL`.
|
|
*/
|
|
// START PROTO list_concat
|
|
// struct list *list_concat(struct list *list, struct list *list2);
|
|
// END PROTO list_concat
|
|
|
|
/*
|
|
** Sort the elements of the list in ascending order.
|
|
** Return the new list.
|
|
*/
|
|
// START PROTO list_sort
|
|
// struct list *list_sort(struct list *list);
|
|
// END PROTO list_sort
|
|
|
|
/*
|
|
** Invert the order of the elements of the list.
|
|
** Return the new list.
|
|
*/
|
|
// START PROTO list_reverse
|
|
// struct list *list_reverse(struct list *list);
|
|
// END PROTO list_reverse
|
|
|
|
/*
|
|
** Split the list at index `index`.
|
|
** First part goes in `list` and contains the element at `index`.
|
|
** Second part is returned.
|
|
** Return `NULL` if `list` is `NULL` or `index` is invalid.
|
|
*/
|
|
// START PROTO list_split
|
|
// struct list *list_split(struct list *list, size_t index);
|
|
// END PROTO list_split
|
|
|
|
#endif /* ! LISTS_H */
|