-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
78 lines (59 loc) · 1.64 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include "dll.h"
/* Application specific data structures */
typedef struct measure {
int id;
float value;
} measure_t;
static void print_measure_details(measure_t *measure) {
printf("%d: %.2f\r\n", measure->id, measure->value);
}
static void print_all_measures(dll_t *dll) {
if (!dll || !dll_empty(dll)) {
return;
}
dll_node_t *ptr = dll->front;
measure_t *data = NULL;
while(ptr) {
data = ptr->data;
print_measure_details(data);
ptr = ptr->next;
}
}
static void print_all_measures_reverse(dll_t *dll) {
if (!dll || !dll_empty(dll)) {
return;
}
dll_node_t *ptr = dll->back;
measure_t *data = NULL;
while(ptr) {
data = ptr->data;
print_measure_details(data);
ptr = ptr->previous;
}
}
int main(int argc, char **argv) {
measure_t *m1 = calloc(1, sizeof(measure_t));
m1->id = 1;
m1->value = 25.5;
measure_t *m2 = calloc(1, sizeof(measure_t));
m2->id = 2;
m2->value = 30.1;
measure_t *m3 = calloc(1, sizeof(measure_t));
m3->id = 3;
m3->value = 99.9888;
dll_t *my_dll = dll_new();
dll_add_data_front(my_dll, m2);
dll_add_data_back(my_dll, m3);
dll_add_data_front(my_dll, m1);
print_all_measures(my_dll);
dll_remove_front(my_dll);
print_all_measures(my_dll);
dll_remove_back(my_dll);
print_all_measures(my_dll);
dll_empty(my_dll) ? printf("DLL is not empty\r\n") : printf("DLL is empty\r\n");
dll_free(my_dll);
print_all_measures(my_dll);
dll_empty(my_dll) ? printf("DLL is not empty\r\n") : printf("DLL is empty\r\n");
return 0;
}