# List **Repository Path**: MacRsh/list ## Basic Information - **Project Name**: List - **Description**: 基于双向链表的实现,提供灵活的节点操作和内存管理功能。该项目支持基本操作,如插入、删除和遍历,适合需要高效数据存取的应用场景。通过链表结构,用户可以方便地管理数据,进行动态调整,满足多种需求。使用简单,易于集成。 - **Primary Language**: C - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 3 - **Forks**: 1 - **Created**: 2024-08-30 - **Last Updated**: 2025-10-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # List [中文文档](README.md) This project provides a simple implementation of a doubly linked list, offering some basic operations for linked lists. ## Features - **Memory Management**: Functions for initialization, de-initialization, and node removal. - **Basic Operations**: Supports insertion and deletion. ## Usage To use this doubly linked list implementation, include this project in your project and include the header file `list.h`. ## Functions ### Initialization and Destruction - `void list_init(List_t *list)`: Initializes the list. - `void list_deinit(List_t *list)`: De-initializes the list. - `List_t *list_new(void)`: Creates a new list. - `void list_del(List_t *list)`: Destroys the list. - `void list_head_init(ListHead_t *head)`: Initializes the list head. - `void list_head_deinit(ListHead_t *head)`: De-initializes the list head. - `ListHead_t *list_head_new(void)`: Creates a new list head. - `void list_head_del(ListHead_t *head)`: Destroys the list head. ### Basic Operations - `int list_push_back(List_t *list, void *data)`: Inserts data at the end of the list. - `int list_push_front(List_t *list, void *data)`: Inserts data at the front of the list. - `int list_push(List_t *list, void *data)`: Inserts data into the list. - `void *list_pop_back(List_t *list)`: Removes and returns data from the end of the list. - `void *list_pop_front(List_t *list)`: Removes and returns data from the front of the list. - `void *list_pop(List_t *list)`: Removes and returns data from the list. - `void *list_first(List_t *list)`: Returns the first data in the list. - `void *list_last(List_t *list)`: Returns the last data in the list. ### List Head Operations - `void list_head_push_back(ListHead_t *list, ListHead_t *head)`: Inserts the list head at the end of the list. - `void list_head_push_front(ListHead_t *list, ListHead_t *head)`: Inserts the list head at the front of the list. - `ListHead_t *list_head_pop_back(ListHead_t *list)`: Removes and returns the list head from the end of the list. - `ListHead_t *list_head_pop_front(ListHead_t *list)`: Removes and returns the list head from the front of the list. - `void list_head_insert(ListHead_t *list, ListHead_t *head)`: Inserts the list head into the list. - `void list_head_remove(ListHead_t *head)`: Removes the list head from the list. - `void list_head_concat(ListHead_t *list, ListHead_t *head)`: Concatenates two lists. - `void list_head_clear(ListHead_t *list)`: Clears the list. - `ListHead_t *list_head_first(ListHead_t *list)`: Returns the first list head in the list. - `ListHead_t *list_head_last(ListHead_t *list)`: Returns the last list head in the list. - `size_t list_head_len(ListHead_t *list)`: Returns the number of list heads in the list. - `bool list_head_is_empty(ListHead_t *list)`: Checks if the list is empty. ### Utility Functions - `void list_clear(List_t *list)`: Clears the list. - `void list_append(List_t *list, List_t *other)`: Appends another list to the current list. - `size_t list_len(List_t *list)`: Returns the number of elements in the list. - `bool list_is_empty(List_t *list)`: Checks if the list is empty. ### Macros - `LIST_FOR_EACH(_pos, _list)`: Macro for iterating through the list. - `LIST_FOR_EACH_SAFE(_pos, _tmp, _list)`: Safe macro for iterating through the list. - `LIST_HEAD_FOR_EACH(_pos, _list)`: Macro for iterating through the list heads. - `LIST_HEAD_FOR_EACH_SAFE(_pos, _tmp, _list)`: Safe macro for iterating through the list heads. ## Simple Example ```c #include #include int main(void) { /* Create a list */ List_t *list = list_new(); /* Insert data */ list_push_back(list, "data1"); list_push_front(list, "data2"); /* Get first data */ void *data = list_first(list); printf("First data: %s\n", (char *)data); /* Iterate through the list */ ListNode_t *pos; LIST_FOR_EACH(pos, list) { printf("Iterating through list: %s\n", (char *)pos->data); } /* Destroy the list */ list_del(list); return 0; } ``` ## License This project is licensed under the Apache-2.0 License. For more details, please refer to the LICENSE file. ## Author (c) 2024, MacRsh