-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
84 lines (62 loc) · 1.64 KB
/
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
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
79
80
81
82
83
84
/* test.c
this program tests all the functions during the developing progress
*/
#include "List.h"
#include <stdio.h>
#include <string.h>
List AddNew(List list);
void showitem(Item item);
int main(void)
{
List list;
InitializeList(&list); // test Initialize
if(ListIsEmpty(&list)) //test ListIsEmpty
printf("the list is empty\n");
else
printf("the list is not empty\n");
// unsigned int counter=0;
// counter=ListItemCount(&list);
Node* pnode;
pnode=(Node*)malloc(sizeof(Node));
Item *pitem;
pitem=(Item*)malloc(sizeof(Item));
pitem->ID=001;
strcpy(pitem->content, "hello list");
pitem->value=1;
pnode->item=*pitem;
list=pnode;
list=AddNew(list); //test AddNew
unsigned int counter=0;
counter=ListItemCount(&list);
printf("there are %u items in the list\n", counter);
// void (*pfun)(Item item)=showitem;
Traverse(&list,showitem); //test Traverse
// EmptyTheList(&list);d
if(ListIsEmpty(&list))
printf("list is empty!\n");
else
printf("list is not empty!\n");
EmptyTheList(&list);
return 0;
}
List AddNew(List list)
{
Item temp;
printf("Input Id for new item:\n");
scanf("%d", &temp.ID);
printf("Input value for new item:\n");
scanf("%d", &temp.value);
printf("Input content for new item:\n");
char c;
while((c=getchar())!='\n'&&c!=EOF)
;
fgets(temp.content, SIZE_CONTENT, stdin);
list=AddToHead(list, temp);
return list;
}
void showitem(Item item)
{
printf("%d\n", item.ID);
printf("%d\n", item.value);
printf("%s\n", item.content);
}