66
77#include "../structs.h"
88
9- /* ---------- List ---------- */
9+ typedef Node * List ; /** Singly linked list */
1010
11- typedef Node * List ;
11+ /* ------------------------------- Constructor ------------------------------ */
1212
13- // Constructor
13+ /**
14+ * @brief Initializes a new singly linked list.
15+ *
16+ * This function sets the given singly linked list to `NULL`.
17+ *
18+ * @param list Singly linked list structure to be initialized.
19+ */
1420void newList (List * list );
1521
16- // Destroyer
17- void destroyList (List * _list );
22+ /* ------------------------------- Destructor ------------------------------- */
1823
19- // Getters
20- unsigned char getHead (const List * _list , void * store , const size_t sizeOfStore );
24+ /**
25+ * @brief Destroys a singly linked list.
26+ *
27+ * This function deallocates all the memory used by the nodes in the singly linked list,
28+ * effectively destroying the list and setting the list pointer to `NULL`.
29+ *
30+ * @param _list Singly linked list to be destroyed.
31+ */
32+ void destroyList (List * _list );
2133
34+ /* --------------------------------- Getters -------------------------------- */
35+
36+ /**
37+ * @brief Retrieves a copy of the data at a specific index in the singly linked list.
38+ *
39+ * This function copies the data from the node at the specified index in the singly linked list
40+ * into the provided storage.
41+ *
42+ * @param _list Singly linked list.
43+ * @param store Storage where the data from the specified index will be copied.
44+ * @param sizeOfStore Size in bytes of the storage.
45+ * @param index Index of data to be copied.
46+ *
47+ * @return 0 if the data was successfully copied, 1 otherwise.
48+ *
49+ * @warning Ensure that the storage provided is large enough to hold the data from the specified
50+ * index.
51+ */
2252unsigned char getElement (const List * _list , void * store , const size_t sizeOfStore ,
2353 const size_t index );
2454
25- unsigned char isListEmpty (List * _list );
55+ /**
56+ * @brief Retrieves the length of the singly linked list.
57+ *
58+ * @param _list Singly linked list whose length is to be determined.
59+ *
60+ * @return Length of the singly linked list.
61+ */
62+ size_t getLength (List * _list );
2663
27- unsigned char isListFull (List * _list , const size_t sizeOfStore );
64+ /**
65+ * @brief Retrieves a copy of the top data inside the singly linked list.
66+ *
67+ * This function copies the data from the top of the singly linked list into the provided
68+ * storage.
69+ *
70+ * @param _list Singly linked list.
71+ * @param store Storage where the data from the top will be copied.
72+ * @param sizeOfStore Size in bytes of the storage.
73+ *
74+ * @return 1 if the data was successfully copied, 0 otherwise.
75+ *
76+ * @warning Ensure that the storage provided is large enough to hold the top data.
77+ */
78+ unsigned char getHead (const List * _list , void * store , const size_t sizeOfStore );
2879
29- size_t getLength (List * _list );
80+ /**
81+ * @brief Checks if the singly linked list is empty.
82+ *
83+ * @param _list Singly linked list to be checked.
84+ *
85+ * @return 1 if the list is empty, 0 otherwise.
86+ */
87+ unsigned char isListEmpty (List * _list );
3088
31- // Methods
32- unsigned char pushElement (List * _list , void * data , const size_t sizeOfData );
89+ /**
90+ * @brief Checks if the singly linked list can accommodate more data.
91+ *
92+ * This function attempts to allocate memory for a new data to determine if the list
93+ * can accommodate more data. If either allocation fails, the list is considered full.
94+ *
95+ * @param _list Singly linked list to be checked.
96+ * @param sizeOfStore Size in bytes of the data to be stored.
97+ *
98+ * @return 1 if the list is full, 0 otherwise.
99+ *
100+ * @warning This function temporarily allocates memory to check for fullness and immediately frees
101+ * it.
102+ */
103+ unsigned char isListFull (List * _list , const size_t sizeOfStore );
33104
105+ /* --------------------------------- Methods -------------------------------- */
106+
107+ /**
108+ * @brief Removes the last data from the singly linked list and copies its data.
109+ *
110+ * This function removes the last data from the singly linked list and copies its data into the
111+ * provided storage.
112+ *
113+ * @param _list Singly linked list from which the last data will be removed.
114+ * @param store Storage where the data will be copied.
115+ * @param sizeOfStore Size in bytes of the storage.
116+ *
117+ * @return 1 if the data was successfully copied to the store, 0 otherwise.
118+ *
119+ * @warning Ensure that the storage provided is large enough to hold data.
120+ */
34121unsigned char popElement (List * _list , void * store , const size_t sizeOfStore );
35122
36- void selectionSort (List * _list , int (* cmp )(const void * a , const void * b ));
123+ /**
124+ * @brief Adds a new data to the end of the singly linked list.
125+ *
126+ * @param _list Singly linked list where the new data will be added.
127+ * @param data Data to be stored at the end of the singly linked list.
128+ * @param sizeOfData Size in bytes of the data to be stored.
129+ *
130+ * @return 1 if the data was successfully added, 0 otherwise.
131+ */
132+ unsigned char pushElement (List * _list , void * data , const size_t sizeOfData );
37133
134+ /**
135+ * @brief Applies a callback function to each data in the singly linked list.
136+ *
137+ * This function iterates through each data in the singly linked list and applies the provided
138+ * callback function to the data.
139+ *
140+ * @param _list Singly linked list whose data will be processed.
141+ * @param callback Function that will be applied to each data.
142+ */
143+ void map (List * _list , void (* callback )(void * element ));
144+
145+ /**
146+ * @brief Randomly shuffles the data of the singly linked list.
147+ *
148+ * @param _list Singly linked list to be shuffled.
149+ */
38150void randomSort (List * _list );
39151
40- typedef void (* action )(void * data , void * data2 );
41-
42- void map (List * _list , action _action , void * punt );
152+ /**
153+ * @brief Sorts the singly linked list using the selection sort algorithm.
154+ *
155+ * This function sorts the data of the singly linked list in ascending order
156+ * based on the comparison function provided. The selection sort algorithm repeatedly
157+ * selects the smallest data from the unsorted portion of the list and swaps it
158+ * with the first unsorted data.
159+ *
160+ * @param _list Singly linked list to be sorted.
161+ * @param cmp Comparison function.
162+ */
163+ void selectionSort (List * _list , int (* cmp )(const void * a , const void * b ));
43164
44165#endif // LIBS__LIST_H_INCLUDED
0 commit comments