-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.c
More file actions
98 lines (81 loc) · 1.55 KB
/
list.c
File metadata and controls
98 lines (81 loc) · 1.55 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include"list.h"
static void CopyToNode(Item item, Node* pnode);
void InitializeList(List* plist) {
plist->head = plist->end = NULL; //what the fuck???
}
bool ListIsEmpty(const List* plist) {
if ((plist->head) == NULL) {
return true;
}
else {
return false;
}
}
bool ListIsFull(const List* plist) { //what mean of it?
Node* pt;
bool full;
pt = (Node*)malloc(sizeof(Node));
if (pt == NULL) {
full = true;
}
else {
full = false;
}
free(pt);
return full;
}
unsigned int ListItemCount(const List* plist) {
unsigned int count = 0;
Node* pnode = plist->head;
while (pnode != NULL)
{
++count;
pnode = pnode->next;
}
return count;
}
bool AddItem(Item item, List* plist) {
Node* pnew;
Node* scan = plist->head;
pnew = (Node*)malloc(sizeof(Node));
if (pnew == NULL) {
return false;
}
CopyToNode(item, pnew);
pnew->next = NULL;
if (scan == NULL) {
plist->head = pnew;
}
else {
while (scan->next != NULL) {
scan = scan->next;
}
scan->next = pnew;
}
return true;
}
void Traverse(const List* plist, void(*pfun)(Item item))
{
Node* pnode = plist->head;
while (pnode != NULL)
{
(*pfun)(pnode->item);
pnode = pnode->next;
}
}
void EmptyTheList(List* plist)
{
Node* psave;
while (plist->head != NULL)
{
psave = (plist->head)->next;
free(plist->head);
plist->head = psave;
}
}
void CopyToNode(Item item, Node* pnode) {
pnode->item = item;
}