-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist.c
More file actions
40 lines (33 loc) · 780 Bytes
/
Copy pathlinkedlist.c
File metadata and controls
40 lines (33 loc) · 780 Bytes
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
#include "linkedlist.h"
Node* LLhead;
int size = 0;
Node* getHead() {
return LLhead;
}
int insertNode(void* content) {
if (LLhead == NULL) {
LLhead = malloc(sizeof(Node));
LLhead->content = content;
LLhead->next = NULL;
size = 1;
return 0;
} else {
Node* currNode = LLhead;
while (currNode->next != NULL) currNode = currNode->next;
currNode->next = malloc(sizeof(Node));
currNode->next->content = content;
currNode->next->next = NULL;
++size;
return size - 1;
}
return -1;
}
void freeLL() {
Node* temp = getHead();
while(temp != NULL) {
Node* tempB = temp->next;
free(temp->content);
free(temp);
temp = tempB;
}
}