-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiList.c
68 lines (40 loc) · 1.16 KB
/
iList.c
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
#include "Types.h"
iList iListCreate(long unsigned int inode, char *dir) { // List create
// Allocate space and assign values
iList l = (iList) malloc(sizeof(ListNode));
l->inode = inode;
l->subList = dirListCreate(dir);
l->link = NULL;
return l;
}
char *iListInsert(iList list, long unsigned int inode, char *dir) { // List insertion -- returns not NULL if the inode exists
iList prev = NULL;
while(list != NULL) { // Parse all nodes in search for inode's listnode
if(list->inode == inode) {
dirListInsert(list->subList, dir);
return list->subList->dir;
}
prev = list;
list = list->link;
}
// Allocate new space, assign values and link
prev->link = iListCreate(inode, dir);
return NULL;
}
void iListPrint(iList list) { // List printing for debugging
while(list != NULL) { // Parse all nodes
printf("[%ld: ", list->inode);
dirListPrint(list->subList);
printf("] -> ");
list = list->link;
}
printf("\n");
}
void iListDestroy(iList list) { // Free space of a List
// Recursively free extra nodes
if(list->link != NULL)
iListDestroy(list->link);
dirListDestroy(list->subList);
// Free current node
free(list);
}