-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistmanager.h
More file actions
75 lines (63 loc) · 1.66 KB
/
Copy pathlistmanager.h
File metadata and controls
75 lines (63 loc) · 1.66 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
#include "linkedlist.h"
#define TRUE 1
#define FALSE 0
#define ARRAY_SIZE 10
#define EMPTY_HEADER_NODE -1
NODE** list_references;
/// Creates a NODE* array to store the heads of the lists
void create_array()
{
list_references = malloc(ARRAY_SIZE * sizeof(NODE*));
if(list_references == NULL)
{
printf("Failed to allocate memory, exit program\n");
exit(EXIT_FAILURE);
}
for(int i = 0; i < ARRAY_SIZE; i++)
{
NODE* current = &list_references[i];
current->nextNode = NULL;
current->nodeData = NULL;
current->nodeSignature = EMPTY_HEADER_NODE;
}
}
/// Important!, needs to be called before program ends!!!!
void dispose()
{
clear_all();
free(list_references);
}
/// Disposes of all the created lists
void clear_all()
{
/// Remember if you create an array of 10 nodes its last index
/// is 9 -.- spend hours over this bug
/// TODO: found out why this behaves like this
for(int i = 0; i < ARRAY_SIZE-1; i++)
{
delete_all_nodes(&list_references[i]);
}
}
/// Creates a new linkedlist header
int create_list(NODE** headRef)
{
if(list_references == NULL)
{
create_array();
}
if(create_node_empty(headRef) == ERROR_MALLOC_FAILED)
{
printf("Failed to allocate memory for list header, exit program");
exit(EXIT_FAILURE);
}
for(int i = 0; i < ARRAY_SIZE; i++)
{
NODE* current = &list_references[i];
if(current->nodeSignature == EMPTY_HEADER_NODE)
{
list_references[i] = &headRef;
return i;
}
}
return -1;
}