-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
189 lines (163 loc) · 3.87 KB
/
main.c
File metadata and controls
189 lines (163 loc) · 3.87 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <stdio.h>
#include <stdlib.h>
#include "single_link_list/link_list.h"
#include "du_link_list/duLinkList.h"
#include "sequence_list/sequence_list.h"
void testSingleLinst() {
LinkList L;
InitList_L(&L);
/*
// 头插法
ListInster_Head(L, 'g');
ListInster_Head(L, 'f');
ListInster_Head(L, 'e');
ListInster_Head(L, 'd');
ListInster_Head(L, 'c');
ListInster_Head(L, 'b');
ListInster_Head(L, 'a');
*/
/*
// 头插法
ListInster_H(L, 5);
int ret = CountList_L(L);
printf("%d", ret);
*/
// 尾插法
ListInster_T(L, 5);
int ret = CountList_L(L);
printf("%d", ret);
/*
int ret = CountList_L(L);
printf("%d\n", ret);
*/
/*
ElemType g;
GetElem_L(L, 10, &g);
printf("%c\n", g);
*/
/*
struct LNode *h;
h = LocateElem_L(L, 'm');
printf("%c\n", h->data);
*/
/*
int ret = ListInert_L(L, 20, 'n');
printf("%d\n", ret);
ElemType j;
GetElem_L(L, 3, &j);
printf("%c\n", j);
*/
/*
ElemType o;
int ret = ListDelete_L(L, 2, &o);
printf("%d\n", ret);
printf("%c\n", o);
*/
}
void testDuLinkList() {
DuLinkList L;
initDuList_L(&L);
/*
// 初始化
printf("%p\n", L->next);
printf("%p\n", L->prior);
*/
/*
// 在最末添加元素
DuListInster_Tail(L, 'a');
DuListInster_Tail(L, 'b');
DuListInster_Tail(L, 'c');
DuListInster_Tail(L, 'd');
printf("%c", L->next->next->next->next->data);
*/
/*
// 尾部插入法
DuListInster_T(L, 5);
printf("%c", L->next->next->next->next->data);
*/
/*
// 头部插入法
DuListInster_H(L, 5);
printf("%c", L->next->next->next->next->data);
*/
/*
// 删除某个位置的元素
DuListInster_T(L, 5); // abcde
ElemType elem;
int site = 3;
ListDelete_DuL(L, site, &elem);
printf("%c\n", elem);
printf("%c\n", L->next->next->next->data);
*/
/*
// 在第i个位置插入元素
DuListInster_T(L, 5); // abcde
ListInert_DuL(L, 3, 'o');
printf("%c\n", L->next->next->next->data);
printf("%c\n", L->next->next->next->next->data);
*/
}
void testSequenceList() {
SqList La, Lb, Lc;
InitList_Sq(&La);
InitList_Sq(&Lb);
InitList_Sq(&Lc);
La.length = 4;
/*
*La.elem = 1;
*(La.elem + 1) = 2;
*(La.elem + 1) = 2;
*(La.elem + 1) = 6;
*/
ListAppend_Sq(&La, 1);
ListAppend_Sq(&La, 2);
ListAppend_Sq(&La, 2);
ListAppend_Sq(&La, 6);
Lb.length = 5;
/*
*Lb.elem = 3;
*(Lb.elem + 1) = 3;
*(Lb.elem + 1) = 4;
*(Lb.elem + 1) = 6;
*(Lb.elem + 1) = 8;
*/
ListAppend_Sq(&Lb, 3);
ListAppend_Sq(&Lb, 3);
ListAppend_Sq(&Lb, 4);
ListAppend_Sq(&Lb, 6);
ListAppend_Sq(&Lb, 8);
MergeList_Sq(La, Lb, &Lc);
ElemInt *lc = Lc.elem;
for (int i = 0; i < Lc.length; i++) {
printf("%d\n", *lc);
++lc;
}
}
void test_merge_by_single_link_list() {
LinkList La;
InitList_L(&La);
ListInster_Tail(La, 1);
ListInster_Tail(La, 2);
ListInster_Tail(La, 2);
ListInster_Tail(La, 6);
LinkList Lb;
InitList_L(&Lb);
ListInster_Tail(Lb, 3);
ListInster_Tail(Lb, 3);
ListInster_Tail(Lb, 4);
ListInster_Tail(Lb, 6);
ListInster_Tail(Lb, 8);
LinkList Lc;
MergeList_L(La, Lb, &Lc);
LNode *p = Lc->next;
while (p) {
printf("%d\n", p->data);
p = p->next;
}
}
int main() {
// testSingleLinst();
// testDuLinkList();
testSequenceList();
// test_merge_by_single_link_list();
}