diff options
| author | Mikkel Thestrup <mithe24@student.sdu.dk> | 2025-12-11 11:00:00 +0100 |
|---|---|---|
| committer | Mikkel Thestrup <mithe24@student.sdu.dk> | 2025-12-11 11:00:00 +0100 |
| commit | 8f512a36a5687b806e27775480878dded7a028ef (patch) | |
| tree | 97c2624fcfefe8bc2f401b674ac31a347cfab0c8 /src | |
| parent | 2d4bdcdbfe9e3db3c0f204e843a271c929fec623 (diff) | |
| download | cycle-detector-8f512a36a5687b806e27775480878dded7a028ef.tar.gz cycle-detector-8f512a36a5687b806e27775480878dded7a028ef.zip | |
I prefer inline typedef
Diffstat (limited to 'src')
| -rw-r--r-- | src/graph.h | 28 | ||||
| -rw-r--r-- | src/linked_list.h | 62 | ||||
| -rw-r--r-- | src/vector.h | 10 |
3 files changed, 34 insertions, 66 deletions
diff --git a/src/graph.h b/src/graph.h index 00d4d6c..e5417b9 100644 --- a/src/graph.h +++ b/src/graph.h @@ -16,21 +16,7 @@ * @details Each vertex is identified by a unique ID and maintains lists of * vertices it points to and vertices that point to it. */ -typedef struct Vertex Vertex; - -/** - * @struct Graph - * @brief A directed graph container. - * @details Maintains an array of all vertices and tracks the total number - * of vertices and edges in the graph. - */ -typedef struct Graph Graph; - -/** - * @struct Vertex - * @brief Represents a single vertex in a directed graph. - */ -struct Vertex { +typedef struct Vertex { /** * @brief Unique identifier for this vertex. * @details A value in the range [0, num_vertices) where num_vertices @@ -53,15 +39,15 @@ struct Vertex { * list is of type (Vertex*). */ Vector *in_neighbours; -}; +} Vertex; /** * @struct Graph - * @brief A directed graph container structure. - * @details The graph is represented using an adjacency list model where - * both incoming and outgoing edges are tracked for each vertex. + * @brief A directed graph container. + * @details Maintains an array of all vertices and tracks the total number + * of vertices and edges in the graph. */ -struct Graph { +typedef struct Graph { /** * @brief The total number of vertices in the graph. * @details Vertices are indexed from 0 to (num_vertices - 1). @@ -81,7 +67,7 @@ struct Graph { * Index i contains the vertex with id = i. */ Vertex *vertices; -}; +} Graph; /** * @brief Allocates and constructs a new graph with n vertices. diff --git a/src/linked_list.h b/src/linked_list.h index 8a075b5..be5f6ab 100644 --- a/src/linked_list.h +++ b/src/linked_list.h @@ -9,26 +9,39 @@ #define LINKED_LIST_H /** - * @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; +typedef 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. + */ + void *data; +} LinkedListNode; /** * @struct LinkedList - * @brief A doubly-linked list container structure. + * @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. */ -struct LinkedList { +typedef struct LinkedList { /** * @brief Pointer to the first node in the list. * @details NULL if the list is empty. @@ -46,32 +59,7 @@ struct LinkedList { * @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. - */ - void *data; -}; +} LinkedList; /** * @brief Allocates and initializes an empty linked list. diff --git a/src/vector.h b/src/vector.h index eaca5f8..c3a86b3 100644 --- a/src/vector.h +++ b/src/vector.h @@ -36,13 +36,7 @@ * as elements are added. It tracks both the number of elements * currently stored (size) and the total allocated space (capacity). */ -typedef struct Vector Vector; - -/** - * @struct Vector - * @brief A dynamic array container structure. - */ -struct Vector { +typedef struct Vector { /** * @brief Array of generic data pointers. * @details A dynamically allocated array of (void*) pointers, @@ -68,7 +62,7 @@ struct Vector { * capacity >= size. */ size_t capacity; -}; +} Vector; /** * @brief Allocates and initializes an empty vector. |