aboutsummaryrefslogtreecommitdiff
path: root/src/linked_list.h
diff options
context:
space:
mode:
authorMikkel Thestrup <mithe24@student.sdu.dk>2025-12-04 16:14:30 +0100
committerMikkel Thestrup <mithe24@student.sdu.dk>2025-12-04 16:14:30 +0100
commit51d1da5bd095fd1b5efdeeda8210651271604427 (patch)
treea31de012c04b837e0fdb8cc67797bbd49cb661e6 /src/linked_list.h
parenteedea9591acf4936d4a2a8eaca289b3311e130b0 (diff)
downloadcycle-detector-51d1da5bd095fd1b5efdeeda8210651271604427.tar.gz
cycle-detector-51d1da5bd095fd1b5efdeeda8210651271604427.zip
Added and changed current docstrings in format that doxygen expects
Diffstat (limited to 'src/linked_list.h')
-rw-r--r--src/linked_list.h142
1 files changed, 122 insertions, 20 deletions
diff --git a/src/linked_list.h b/src/linked_list.h
index 4e6dadf..0da0c25 100644
--- a/src/linked_list.h
+++ b/src/linked_list.h
@@ -1,50 +1,152 @@
+/**
+ * @file linked_list.h
+ * @brief Doubly-linked list implementation.
+ * @details This module provides a generic doubly-linked list data structure
+ * that can store pointers to any data type. The list maintains both
+ * head and tail pointers for efficient operations at both ends.
+ */
+
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
-// A linked list containing any type of pointer.
-// The linked list does _not_ own its elements.
-
+/**
+ * @struct LinkedList
+ * @brief A doubly-linked list container.
+ * @details Maintains references to the first and last nodes in the list,
+ * as well as the current number of elements.
+ */
typedef struct LinkedList LinkedList;
+
+/**
+ * @struct LinkedListNode
+ * @brief A node within a doubly-linked list.
+ * @details Each node contains pointers to the next and previous nodes,
+ * allowing bidirectional traversal, and a generic data pointer.
+ */
typedef struct LinkedListNode LinkedListNode;
+/**
+ * @struct LinkedList
+ * @brief A doubly-linked list container structure.
+ */
struct LinkedList {
+ /**
+ * @brief Pointer to the first node in the list.
+ * @details NULL if the list is empty.
+ */
LinkedListNode *head;
+
+ /**
+ * @brief Pointer to the last node in the list.
+ * @details NULL if the list is empty.
+ */
LinkedListNode *tail;
+
+ /**
+ * @brief The number of nodes currently in the list.
+ * @details Updated whenever nodes are added or removed.
+ */
int size;
};
+/**
+ * @struct LinkedListNode
+ * @brief A single node in a doubly-linked list structure.
+ */
struct LinkedListNode {
+ /**
+ * @brief Pointer to the next node in the list.
+ * @details NULL if this is the last node.
+ */
LinkedListNode *next;
+
+ /**
+ * @brief Pointer to the previous node in the list.
+ * @details NULL if this is the first node (head).
+ */
LinkedListNode *prev;
+
+ /**
+ * @brief Generic pointer to the node's data.
+ * @details The caller is responsible for managing the memory
+ * pointed to by this pointer. This pointer can store any
+ * data type (int*, char*, struct*, etc.).
+ */
void *data;
};
-// Allocate and initialize an empty linked list.
-// Returns: a pointer to the new linked list, or NULL on error.
-// Post: the caller owns the linked list.
+/**
+ * @brief Allocates and initializes an empty linked list.
+ *
+ * @return A pointer to the newly created linked list, or NULL if memory
+ * allocation fails.
+ *
+ * @note The caller is responsible for freeing the returned linked list
+ * using linked_list_delete().
+ */
LinkedList *linked_list_new();
-// Deallocate the given linked list, including all nodes
-// (but _not_ the data they point to, the user owns that).
+/**
+ * @brief Deallocates the given linked list and all its nodes.
+ *
+ * @param ll Pointer to the linked list to delete. If NULL, this function
+ * does nothing.
+ *
+ * @note This function deallocates only the list structure and nodes, not
+ * the data they point to. The caller retains ownership of the data.
+ */
void linked_list_delete(LinkedList *ll);
-// Append a the given element to the list.
-// The linked list does _not_ take ownership over the element
-// (only the linked list node).
-// Returns: a pointer to the node with the new element, or NULL on error.
+/**
+ * @brief Appends an element to the end of the linked list.
+ *
+ * @param ll Pointer to the linked list.
+ * @param elem Pointer to the element to append.
+ *
+ * @return A pointer to the newly created node containing the element,
+ * or NULL if memory allocation fails.
+ *
+ * @note The linked list does not take ownership of the element itself,
+ * only the node structure. The caller retains ownership of the
+ * data.
+ */
LinkedListNode *linked_list_append(LinkedList *ll, void *elem);
-// Remove and return the first element from the given list.
-// Pre: ll->size != 0
+/**
+ * @brief Removes and returns the first element from the linked list.
+ *
+ * @param ll Pointer to the linked list.
+ *
+ * @return The data pointer of the removed first element.
+ *
+ * @pre The list must not be empty (ll->size != 0).
+ */
void *linked_list_popfront(LinkedList *ll);
-// Find the linked list node containing the given element.
-// Returns: a pointer to the found node, or NULL if the element was not found.
+/**
+ * @brief Finds the linked list node containing the given element.
+ *
+ * @param ll Pointer to the linked list.
+ * @param elem Pointer to the element to search for.
+ *
+ * @return A pointer to the node containing the element, or NULL if the
+ * element was not found in the list.
+ */
LinkedListNode *linked_list_find(LinkedList *ll, void *elem);
-// Remove the given node from the given linked list (and deallocate it).
-// Pre: node must belong to ll
-// Returns: node->data
+/**
+ * @brief Removes the given node from the linked list and deallocates it.
+ *
+ * @param ll Pointer to the linked list.
+ * @param node Pointer to the node to remove.
+ *
+ * @return The data pointer stored in the removed node.
+ *
+ * @pre The node must belong to the linked list ll.
+ *
+ * @note The node structure is deallocated, but the data is not. The
+ * caller retains ownership of the returned data.
+ */
void *linked_list_remove(LinkedList *ll, LinkedListNode *node);
-#endif // LINKED_LIST_H
+#endif // !LINKED_LIST_H