-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinked_list_test.c
38 lines (33 loc) · 1.04 KB
/
linked_list_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
#include <stdlib.h>
#include <stdio.h>
#include "linked_list_test.h"
#include "linked_list.h"
#include "item.h"
bool TestList(void)
{
LinkedList *list;
InitList(&list, FreeItem, MatchItem);
Item *prevItem = NULL;
Item *newItem;
double number;
for (register int i = 1; i < 10; i++) {
number = rand()/100.0;
MakeItem(&newItem, i, number);
InsertListItem(list, newItem, prevItem);
prevItem = newItem;
printf("insert item into list: %d %f %d\n", i, number, list->len);
}
Item tmpItem;
tmpItem.id = 4;
DeleteListItem(list, &tmpItem);
printf("delete item from list: %d %f %d\n", tmpItem.id, tmpItem.number, list->len);
tmpItem.id = 5;
DeleteListItem(list, &tmpItem);
printf("delete item from list: %d %f %d\n", tmpItem.id, tmpItem.number, list->len);
tmpItem.id = 6;
DeleteListItem(list, &tmpItem);
printf("delete item from list: %d %f %d\n", tmpItem.id, tmpItem.number, list->len);
TraverseList(list, DisplayItem);
FreeList(list);
return true;
}