Repository navigation
Expand file tree
/
Copy pathlist_example.p
More file actions
144 lines (123 loc) · 2.52 KB
/
Copy pathlist_example.p
File metadata and controls
144 lines (123 loc) · 2.52 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import list
typedef struct list list
typedef struct listNode listNode
// 构造一个具体的listNode
listNode * makeNode(int val)
{
listNode * node = createListNode()
node->value = malloc(sizeof(int))
*(int *(node->value)) = val // 大小一致,直接转换
return node
}
list makeList()
{
int compare(void * a, void * b)
{
int av = *(int *(a))
int bv = *(int *(b))
if (av < bv) return -10
if (av > bv) return 10
return 0
}
list l = createList()
l.match = compare//导致计算上一个fp的位置
return l
}
void test_insertSortedList()
{
list l = makeList()
l.insertSortedList(makeNode(-1))
l.insertSortedList(makeNode(1))
l.insertSortedList(makeNode(-20))
l.insertSortedList(makeNode(-20))
l.insertSortedList(makeNode(-20))
l.insertSortedList(makeNode(-100000))
l.insertSortedList(makeNode(2000))
l.insertSortedList(makeNode(100))
listNode * cur = l.head->next
while(cur != NULL)
{
write *(cur->value)
cur = cur->next
}
}
void test_appendList()
{
list l = makeList()
void opera(list * l,listNode * node){}
l.append(makeNode(-1))
l.append(makeNode(1))
l.append(makeNode(-20))
l.append(makeNode(-20))
l.append(makeNode(-20))
l.append(makeNode(-100000))
l.append(makeNode(2000))
l.append(makeNode(100))
listNode * cur = l.head->next
while(cur != NULL)
{
write *(cur->value)
cur = cur->next
}
}
void test_removeList()
{
list l = makeList()
int i = 100
l.insertSortedList(makeNode(-1))
l.insertSortedList(makeNode(1))
l.insertSortedList(makeNode(-20))
l.insertSortedList(makeNode(100))
l.insertSortedList(makeNode(2001515))
l.insertSortedList(makeNode(5453))
l.insertSortedList(makeNode(5675541))
listNode * cur = l.head->next
l.removeList(&i)
i = 2001515
l.removeList(&i)
i = 5453
l.removeList(&i)
cur = l.head->next
while(cur != NULL)
{
write *(cur->value)
cur = cur->next
}
}
void test_pop()
{
list l = makeList()
l.insertSortedList(makeNode(-1))
l.insertSortedList(makeNode(1))
l.insertSortedList(makeNode(-20))
l.insertSortedList(makeNode(100))
l.insertSortedList(makeNode(2001515))
l.insertSortedList(makeNode(5453))
l.insertSortedList(makeNode(5675541))
l.popRight()
l.popLeft()
l.popLeft()
listNode * cur = l.head->next
while(cur != NULL)
{
write *(cur->value)
cur = cur->next
}
}
void testMatch(){
list l = makeList()
int a = 1
int b = 1
write l.match(&a,&b)
}
void main()
{
testMatch()
test_insertSortedList()
write "---------------"
test_appendList()
write "---------------"
test_removeList()
write "---------------"
test_pop()
}