-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedlist_test.c
executable file
·50 lines (39 loc) · 1.13 KB
/
linkedlist_test.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "value.h"
#include "linkedlist.h"
int main(void) {
Value *val1 = malloc(sizeof(Value));
val1->type = INT_TYPE;
val1->i = 23;
Value *val2 = malloc(sizeof(Value));
val2->type = STR_TYPE;
val2->s = malloc(10 * sizeof(char));
strcpy(val2->s, "tofu");
Value *head = makeNull();
head = cons(val1, head);
head = cons(val2, head);
display(head);
printf("Length = %i\n", length(head));
printf("Empty? %i\n", isNull(head));
Value *reversed = reverse(head);
display(reversed);
Value *val3 = malloc(sizeof(Value));
val3->type = DOUBLE_TYPE;
val3->d = 23.2;
Value *val4 = malloc(sizeof(Value));
val4->type = DOUBLE_TYPE;
val4->d = 54.2;
Value *val5 = malloc(sizeof(Value));
val5->type = INT_TYPE;
val5->i = 44;
Value *consCell = cons(val4, val5);
Value *head2 = cons(val3, consCell);
display(head2);
head2 = cons(head, head2);
display(head2);
Value *emptyList = makeNull();
display(emptyList);
return 0;
}