-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_linked_list.h
More file actions
44 lines (36 loc) · 908 Bytes
/
simple_linked_list.h
File metadata and controls
44 lines (36 loc) · 908 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
41
42
43
44
#pragma once
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
struct Node *next;
uint64_t value;
} Node;
void simple_linked_list_print_node(Node *node) {
printf("%p | value - %llu, next - %p\n", node, node->value, node->next);
}
void simple_linked_list_print_list(Node *list) {
Node *tmp = list;
while (tmp != NULL) {
simple_linked_list_print_node(tmp);
tmp = tmp->next;
}
}
Node *simple_linked_list_init(ScratchAlloc *scr, uint64_t val) {
Node *head = scratch_alloc(scr, sizeof(Node));
head->next = NULL;
head->value = val;
return head;
}
void simple_linked_list_append(ScratchAlloc *scr, Node **list, uint64_t value) {
if (*list == NULL) {
*list = simple_linked_list_init(scr, value);
return;
}
Node *tmp = *list;
while (tmp->next != NULL) {
tmp = tmp->next;
}
Node *new_node = simple_linked_list_init(scr, value);
tmp->next = new_node;
}