-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.c
More file actions
42 lines (36 loc) · 854 Bytes
/
list.c
File metadata and controls
42 lines (36 loc) · 854 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
#include "list.h"
list_t *createEmptyList() {
list_t *list = (list_t *) malloc(sizeof(list_t));
list->first = NULL;
list->last = NULL;
list->count = 0;
return list;
}
void *getFirstInfo(list_t const *list) {
return list->first->info;
}
void *getLastInfo(list_t const *list) {
return list->last->info;
}
int isEmpty(list_t const *list) {
return list->count == 0;
}
void addInfo(list_t *list, void *info) {
node_t *tmp = malloc(sizeof(node_t));
tmp->info = info;
tmp->previous = NULL;
tmp->next = NULL;
if (isEmpty(list)) {
list->count++;
list->first = tmp;
list->last = tmp;
} else {
list->count++;
list->last->next = tmp;
tmp->previous = list->last;
list->last = tmp;
}
}
int getCount(list_t const *list) {
return list->count;
}