-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinked_list.c
More file actions
79 lines (69 loc) · 1.49 KB
/
linked_list.c
File metadata and controls
79 lines (69 loc) · 1.49 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
#include "linked_list.h"
#include "graph.h"
struct llNode *
createLLNode(void *data) {
struct llNode *node = malloc(sizeof(struct llNode));
if (node == NULL) {
printf(" There was some problem with memory allocation");
return NULL;
}
node->data = data;
node->next = NULL;
return node;
}
void addToLLStart(struct linkedList *list, void *data) {
struct llNode *node = createLLNode(data);
if (list->head == NULL) {
list->head = node;
list->tail = node;
} else {
node->next = list->head;
list->head = node;
}
}
void addToLLEnd(struct linkedList *list, void *data) {
struct llNode *node = createLLNode(data);
if (list->tail == NULL) {
list->head = node;
list->tail = node;
} else {
list->tail->next = node;
list->tail = node;
}
}
void *removeFromLL(struct linkedList *list, void *data) {
/*struct llNode *node = list->head;
while (node != NULL) {
if (node->data == *data)
}*/
}
/*void
printLL(struct linkedList *list) {
if(list->head == NULL) {
printf("Empty list\n");
} else {
struct llNode *node = list->head;
do {
printf(" -> %d", node->data);
node = node->next;
} while (node != NULL);
printf(" <- TAIL\n");
}
}
*/
struct linkedList *createLinkedList() {
struct linkedList *list = malloc(sizeof(struct linkedList));
list->head = NULL;
list->tail = NULL;
return list;
}
/*void main() {
struct linkedList *list = createLinkedList();
int a = 5;
addToLLStart(list, a);
int b = 6;
addToLLStart(list, b);
int c = 7;
addToLLEnd(list, c);
printLL(list);
}*/