-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.c
executable file
·57 lines (44 loc) · 878 Bytes
/
list.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
#include "basis.h"
#include "list.h"
Node *node_create(void *data){
Node *new_node = malloc(sizeof(Node));
new_node->data = data;
new_node->next = NULL;
return new_node;
}
void node_destroy(Node *node){
free(node);
}
size_t list_size(List *list){
return list->size;
}
int list_push_back(List *list, Node *node){
if(!list)
return 1;
size_t size = list_size(list);
if(0 == size){
list->head = node;
list->tail = node;
goto add_node;
}
list->tail->next = node;
list->tail = node;
add_node:
list->size++;
return 0;
}
int list_push_front(List *list, Node *node){
if(!list)
return 1;
size_t size = list_size(list);
if(0 == size){
list->head = node;
list->tail = node;
goto add_node;
}
node->next = list->head;
list->head = node;
add_node:
list->size++;
return 0;
}