-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsinglelinkedlist.h
More file actions
367 lines (292 loc) · 10.1 KB
/
singlelinkedlist.h
File metadata and controls
367 lines (292 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*******************************************************************************************************
* NAME: singlelinkedlist.h
*
* PURPOSE: Defines a general template for single linked lists, including
* the different needed functions
*
* GLOBAL VARIABLES: None
*
*
* DEVELOPMENT HISTORY:
*
* Date Author Change Id Release Description Of Change
* ---------- --------------- --------- ------- -----------------------------------
* 27-10-2024 Tiago Rodrigues 1 Prolog and definition of operations
* 24-01-2025 Tiago Rodrigues 1 Changed all operations to use void *
* 27-01-2025 Tiago Rodrigues 1 Added Comments to Functions
*
*******************************************************************************************************/
#ifndef SINGLELINKEDLIST_H
#define SINGLELINKEDLIST_H
/* 0 copyright/licensing */
/**********************************************************************
*
* 2024 Tiago Filipe Rodrigues tiagorodrigues1590@hotmail.com
*
***********************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/* 1 includes */
/*****************************************************/
#include <stdint.h>
/*****************************************************/
/* 2 defines */
/*****************************************************/
/*****************************************************/
/* 3 external declarations */
/*****************************************************/
/*****************************************************/
/* 4 typedefs */
/*****************************************************/
/*****************************************************/
/* 5 global variable declarations */
/*****************************************************/
/*****************************************************/
/* 6 function prototypes */
/*****************************************************/
/******************************************************************
*
* FUNCTION NAME: create_node
*
* PURPOSE: Allocates the needed memory for a node of the singly linked list
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* node void** I/O pointer to the memory position of the node to allocate
*
*
* RETURNS: void
*
*
*
*****************************************************************/
void create_node(void** node);
/******************************************************************
*
* FUNCTION NAME: give_node_value
*
* PURPOSE: Allocates and gives a value to a node already allocated
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* node void* I/O pointer to the memory position of the node
* value1 void* I pointer to the memory position of the data to push into the node
* size_of_datatype uint64_t I byte size of datatype to place in the node
*
* RETURNS: void
*
*
*
*****************************************************************/
void give_node_value(void* node, void *value1, uint64_t size_of_datatype);
/******************************************************************
*
* FUNCTION NAME: add_node_to_head
*
* PURPOSE: Adds a node to the head of a linked list
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* head void** I/O pointer to the memory position of the head of the list
* node void* I pointer to the memory position of the node to add to the list
*
* RETURNS: void
*
*
*
*****************************************************************/
void add_node_to_head(void** head, void* node);
/******************************************************************
*
* FUNCTION NAME: add_node_to_tail
*
* PURPOSE: Adds a node to the tail of a linked list
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* head void** I/O pointer to the memory position of the head of the list
* node void* I pointer to the memory position of the node to add to the list
*
* RETURNS: void
*
*
*
*****************************************************************/
void add_node_to_tail(void** head, void* node); // ** needed in case head in null
/******************************************************************
*
* FUNCTION NAME: add_node_in_index_n
*
* PURPOSE: Adds a node to index n of a linked list
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* head void** I/O pointer to the memory position of the head of the list
* node void* I pointer to the memory position of the node to add to the list
* position uint64_t I position to add node to the linked list
*
* RETURNS: void
*
*
*
*****************************************************************/
void add_node_in_index_n(void** head, void* node, uint64_t position);
/******************************************************************
*
* FUNCTION NAME: remove_head_node
*
* PURPOSE: removes the head of a linked list
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* head void** I/O pointer to the memory position of the head of the list
*
*
* RETURNS: void
*
*
*
*****************************************************************/
void remove_head_node(void** head);
/******************************************************************
*
* FUNCTION NAME: remove_tail_node
*
* PURPOSE: removes the tail of a linked list
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* head void** I/O pointer to the memory position of the head of the list
*
*
* RETURNS: void
*
*
*
*****************************************************************/
void remove_tail_node(void** head);
/******************************************************************
*
* FUNCTION NAME: remove_node_in_index_n
*
* PURPOSE: removes node at index n of a linked list
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* head void** I/O pointer to the memory position of the head of the list
* position uint64_t I position to remove node in the linked list
*
* RETURNS: void
*
*
*
*****************************************************************/
void remove_node_in_index_n(void** head, uint64_t position);
/******************************************************************
*
* FUNCTION NAME: next_node
*
* PURPOSE: changes pointer to the next node of that pointer
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* node void** I/O pointer to the memory position of the node
*
*
* RETURNS: void
*
*
*
*****************************************************************/
void next_node(void** node);
/******************************************************************
*
* FUNCTION NAME: get_next_node
*
* PURPOSE: returns a pointer to the next node of a node
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* node void* I pointer to the memory position of the node
*
*
* RETURNS: void* (memory position of the next node to the given node )
*
*
*
*****************************************************************/
void* get_next_node(void* node);
/******************************************************************
*
* FUNCTION NAME: get_value
*
* PURPOSE: Returns the memory position of the value that is currently in the given node
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* node void* I pointer to the memory position of the node
*
*
* RETURNS: void* (pointer to the memory position of the value in the node)
*
*
*
*****************************************************************/
void* get_value(void* node);
/******************************************************************
*
* FUNCTION NAME: get_value_in_index_n
*
* PURPOSE: Returns the memory position of the value that is currently in the node in index n
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* head void* I pointer to the memory position of the head of the list
* position uint64_t I position of the node to return value
*
* RETURNS: void* (pointer to the memory position of the value in the node at index n)
*
*
*
*****************************************************************/
void* get_value_in_index_n(void* head, uint64_t n);
// void print_list(void* head);
/******************************************************************
*
* FUNCTION NAME: free_linked_list
*
* PURPOSE: frees a linked list
*
* ARGUMENTS:
*
* ARGUMENT TYPE I/O DESCRIPTION
* head void** I/O pointer to the memory position of the head of the list
*
*
* RETURNS: void
*
*
*
*****************************************************************/
void free_linked_list(void** head);
/*****************************************************/
/* 7 function declarations */
/*****************************************************/
/*****************************************************/
#ifdef __cplusplus
}
#endif
#endif