-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolutions.json
More file actions
450 lines (450 loc) · 60.4 KB
/
Copy pathsolutions.json
File metadata and controls
450 lines (450 loc) · 60.4 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
[
{
"id": "DC01PE06",
"code": "#include \"allinclude.h\" //DO NOT edit this line\n// 通过交换,令 a >= b >= c\nvoid Descend(int &a, int &b, int &c) \n{ \n if(a<b)\n {\n a=a+b;\n b=a-b;\n a=a-b;\n }\n if(a<c)\n {\n a=a^c;\n c=a^c;\n a=a^c;\n }\n if(b<c)\n {\n int t;\n t=b;\n b=c;\n c=t;\n }\n}"
},
{
"id": "DC01PE08",
"code": "#include \"allinclude.h\" //DO NOT edit this line\n#include <math.h>\nfloat Polynomial(int n, int a[], float x0) \n{ // Add your code here\n float result=0;\n int i=0;\n while(i<=n)\n {\n result+=a[i]*pow(x0,i);\n i++;\n }\n return result;\n}"
},
{
"id": "DC01PE11",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Fibonacci(int k, int m, int &f) { \n //求k阶第m项值的函数\n //能求得k阶m项的值f,则返回OK,否则ERROR\n //K阶斐波那契数列的前k-1项均为0(0~k-2),第k-1项为1,以后的每一项都是前k项的和\n //化简得迭代公式:\n //①:f(m)=f(m-1)+f(m-2)+…+f(m-k) \n //②:f(m-1)=f(m-2)+f(m-3)+…+f(m-k-1) \n //①-②: f(m)-f(m-1)=f(m-1)-f(m-k-1)->f(m)=2f(m-1)-f(m-k-1) \n if(m<0||k<=1)\n {\n return ERROR;\n }\n \n int a[1000];\n for(int i=0;i<k-1;i++)\n {\n a[i]=0;\n }\n a[k-1]=1;\n a[k]=1;\n if(k>=m)\n {\n f=a[m];\n return OK;\n }\n for(int i=k+1;i<=m;i++)\n {\n a[i]=2*a[i-1]-a[i-k-1];\n }\n f=a[m];\n return OK;\n}"
},
{
"id": "DC01PE18",
"code": "#include \"allinclude.h\" //DO NOT edit this line\n#include <math.h>\nStatus Series(int a[], int n) { \n if(n==0)\n return ERROR;\n int mul=1;\n for(int i=1;i<=n;i++)\n {\n mul*=i;\n a[i-1]=mul*pow(2,i);\n if(a[i-1]>MAXINT)\n return EOVERFLOW;\n }\n return OK;\n}"
},
{
"id": "DC01PE20",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid printName(stuType student[], int index[], int n)\n{ \n for(int i=0;i<n;i++)\n {\n printf(\"%s\\n\",student[index[i]].name);\n }\n}"
},
{
"id": "DC01PE21",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nfloat highestScore(stuType *student[], int n)\n{ \n float max=0.0;\n for(int i=0;i<n;i++)\n {\n if(student[i]->score>max)\n {\n max=student[i]->score;\n }\n }\n return max;\n}"
},
{
"id": "DC01PE22",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid printFirstName_HighestScore(stuType *student[], int n)\n{ \n char* mName;\n float mMax=0.0;\n for(int i=0;i<n;i++)\n {\n if(mMax<student[i]->score)\n {\n mMax=student[i]->score;\n mName=(char*)&(student[i]->name);\n }\n }\n for(int i=0;i<4;i++)\n {\n printf(\"%c\",mName[i]);\n }\n printf(\"\\n%.2f\\n\",mMax);\n}"
},
{
"id": "DC01PE23",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid printLastName_HighestScore(stuType *student[], int n)\n{ \n char* mName;\n float mMax=0.0;\n for(int i=0;i<n;i++)\n {\n if(mMax<=student[i]->score)\n {\n mMax=student[i]->score;\n mName=(char*)&(student[i]->name);\n }\n }\n for(int i=0;i<4;i++)\n {\n printf(\"%c\",mName[i]);\n }\n printf(\"\\n%.2f\\n\",mMax);\n}"
},
{
"id": "DC01PE30",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStrSequence* reverseStr(StrSequence* strSeq)\n/*返回一个结构体,该结构体将strSeq中的字符串逆序存放*/\n{ \n int len=strSeq->length;//取出结构体的字符串长度\n ElemType* pElem=strSeq->elem;//取出结构体的字符串\n\n ElemType* str=(ElemType*)malloc(len*sizeof(ElemType));\n \n \n StrSequence newSS;\n newSS.elem=str;//返回的结构体的字符串\n newSS.length=len;//返回的结构体的长度\n StrSequence* pnewSS=&newSS;\n\n for(int i=0;i<len;i++)\n {\n str[i]=*(pElem+len-i-1);\n }\n return pnewSS;\n}"
},
{
"id": "DC01PE49",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus CreateSequence(Sequence &S, int n, ElemType *a) { \n if(n<=0)\n {\n return ERROR;\n }\n S.elem=a;\n S.length=n;\n return OK;\n}"
},
{
"id": "DC01PE61",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nLinkList MakeNode(ElemType x) { \n LNode n;\n LinkList pn=&n;\n n.data=x;\n n.next=nullptr;\n return pn;\n}"
},
{
"id": "DC01PE63",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nLinkList CreateLinkList(ElemType x, ElemType y) { \n int nodeSize=sizeof(ElemType)+sizeof(LinkList);\n LinkList pn1=(LinkList)malloc(nodeSize);\n LinkList pn2=(LinkList)malloc(nodeSize);\n pn1->data=x;\n pn1->next=pn2;\n pn2->data=y;\n pn2->next=nullptr;\n return pn1;\n}"
},
{
"id": "DC01PE65",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nLinkList CreateOrdLList(ElemType x, ElemType y) { \n if(x>y)\n {\n x=x^y;\n y=x^y;\n x=x^y;\n }\n //使x小y大\n int nodeSize=sizeof(ElemType)+sizeof(LinkList);\n LinkList pn1=(LinkList)malloc(nodeSize);\n LinkList pn2=(LinkList)malloc(nodeSize);\n pn1->data=x;\n pn1->next=pn2;\n pn2->data=y;\n pn2->next=nullptr;\n return pn1;\n}"
},
{
"id": "DC02PE03",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus StackEmpty_Sq(SqStack S) { \n if(S.top==0)\n {\n return TRUE;\n }\n return FALSE;\n}"
},
{
"id": "DC02PE05",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus GetTop_Sq(SqStack S, ElemType &e) { \n if(S.top==0)\n return ERROR;\n e=*(S.elem+S.top-1);\n return OK;\n}"
},
{
"id": "DC02PE07",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Pop_Sq(SqStack &S, ElemType &e) { \n if(S.top==0)\n return ERROR;\n e=*(S.elem+S.top-1);\n S.top-=1;\n return OK;\n}"
},
{
"id": "DC02PE11",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus InitStack_Sq2(SqStack2 &S, int size, int inc) { \n if(inc<=0||size<=0)\n {\n return ERROR;\n }\n \n ElemType* pMem=(ElemType*)malloc(size);\n S.elem=pMem;\n S.top=pMem;\n S.size=size;\n S.increment=inc;\n return OK;\n}"
},
{
"id": "DC02PE13",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus StackEmpty_Sq2(SqStack2 S) { \n if(S.elem==S.top)\n return TRUE;\n return FALSE;\n}"
},
{
"id": "DC02PE15",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Push_Sq2(SqStack2 &S, ElemType e) { \n *(S.top)=e;\n S.top+=sizeof(ElemType);\n return OK;\n}"
},
{
"id": "DC02PE17",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Pop_Sq2(SqStack2 &S, ElemType &e) { \n if(S.elem==S.top)\n {\n return ERROR;\n }\n S.top-=sizeof(ElemType);\n e=*(S.top);\n return OK;\n}"
},
{
"id": "DC02PE19",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus CopyStack_Sq(SqStack S1, SqStack &S2) { \n S2.elem=S1.elem;\n S2.top=S1.top;\n S2.size=S1.size;\n S2.increment=S1.increment;\n return TRUE;\n}"
},
{
"id": "DC02PE20",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid Conversion(int N, int rd)\n{ \n SqStack S;\n InitStack_Sq(S,MAXSIZE,INCREMENT);\n \n ElemType mod;\n while(N!=0)\n {\n mod=N%rd;\n Push_Sq(S,mod);\n N/=rd;\n }\n \n ElemType print;\n while(!StackEmpty_Sq(S))\n {\n Pop_Sq(S,print);\n printf(\"%d\",print);\n }\n DestroyStack_Sq(S);\n}"
},
{
"id": "DC02PE21",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus matchBracketSequence(char* exp, int n)\n{ \n\n SqStack S;\n InitStack_Sq(S,MAXSIZE,INCREMENT);\n ElemType t;\n char e;//括号串里的元素\n \n for(int i=0;i<n;i++)\n {\n e=exp[i];\n if(e=='{' || e=='[' || e=='(')\n {\n Push_Sq(S,e);\n }\n else\n {\n if(StackEmpty_Sq(S))\n {\n goto wrong;\n } \n else {\n Pop_Sq(S,t);\n if((t=='{'&&e=='}')||(t=='['&&e==']')||(t=='('&&e==')'))\n {\n continue;\n }\n else \n {\n goto wrong;\n }\n }\n\n }\n }\n \n if(StackEmpty_Sq(S))\n {\n DestroyStack_Sq(S);\n return TRUE;\n }\n \nwrong:\n DestroyStack_Sq(S);\n return FALSE;\n\n}"
},
{
"id": "DC02PE23",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint QueueLength_Sq(SqQueue Q) { \n if(Q.front>Q.rear)\n return Q.maxSize - Q.front + Q.rear;\n return Q.rear - Q.front;\n}"
},
{
"id": "DC02PE25",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus EnCQueue(CTagQueue &Q, ElemType x) { \n if(Q.tag)\n {\n return ERROR;\n }\n Q.elem[Q.rear]=x;\n Q.rear++;\n Q.rear%=MAXQSIZE;//这一行也可以替换成下面那段注释里的代码\n /*\n if(Q.rear==MAXQSIZE)\n {\n Q.rear=0;\n }\n */\n if(Q.front==Q.rear)\n {\n Q.tag=1;\n }\n return OK;\n}\n\nStatus DeCQueue(CTagQueue &Q, ElemType &x){\n if(Q.front==Q.rear && Q.tag==0)\n {\n return ERROR;\n }\n x=Q.elem[Q.front];\n Q.front++;\n Q.front%=MAXQSIZE;\n if(Q.front==Q.rear)\n {\n Q.tag=0;\n }\n return OK;\n}"
},
{
"id": "DC02PE27",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus EnCQueue(CLenQueue &Q, ElemType x) { \n if(Q.length==MAXQSIZE)\n return ERROR;\n Q.rear++;\n Q.rear%=MAXQSIZE;\n Q.elem[Q.rear]=x;\n Q.length++;\n return OK;\n}\n\nStatus DeCQueue(CLenQueue &Q, ElemType &x){\n if(Q.length==0)\n return ERROR;\n int index=Q.rear-Q.length+1;//指向队头元素\n if(index<0)\n index = Q.rear - Q.length + 1 + MAXQSIZE;\n x = Q.elem[index];\n Q.length--;\n return OK;\n}"
},
{
"id": "DC02PE32",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nlong Fib(int k, int n) {\n\n if (n < 0 || k <= 1)\n {\n return ERROR;\n }\n\n SqQueue Sq;\n ElemType* pBase = (ElemType*)malloc((k + 1) * sizeof(ElemType));\n if (pBase == nullptr)\n return ERROR;\n memset(pBase, 0, (k + 1) * sizeof(ElemType));\n\n Sq.base = pBase;\n Sq.front = 0;\n Sq.rear = k;\n Sq.maxSize = k + 1;\n *(Sq.base + k - 1) = 1;\n\n\n if (n < k)\n return *(Sq.base + n);\n for (int i = k; i <= n; i++)\n {\n int j=Sq.front;\n while(j!=Sq.rear)\n {\n *(Sq.base + Sq.rear)+=*(Sq.base+j);\n j++;\n j%=Sq.maxSize;\n }\n Sq.rear++;\n Sq.rear%=Sq.maxSize;\n Sq.front++;\n Sq.front%=Sq.maxSize;\n *(Sq.base + Sq.rear) = 0;\n }\n \n int index=Sq.rear-1;\n if(index<0)\n {\n index+=Sq.maxSize;//index=Sq.maxSize-1;\n }\n return *(Sq.base+index);\n \n}"
},
{
"id": "DC02PE33",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nchar Compare(SqList A, SqList B) \n{ \n int minLen = A.length;\n char result = 0;\n if(A.length==B.length)\n {\n result = '=';\n }\n else if(A.length<B.length)\n {\n result = '<';\n }\n else \n {\n result = '>';\n minLen=B.length;\n }\n\n \n for(int i=0;i<minLen;i++)\n {\n if(A.elem[i]>B.elem[i])\n return '>';\n if(A.elem[i]<B.elem[i])\n return '<';\n if(A.elem[i]==B.elem[i])\n continue;\n }\n \n return result;\n}"
},
{
"id": "DC02PE35",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid Inverse(SqList &L) \n{ \n for(int i=0;i<L.length/2;i++)\n {\n L.elem[i]=L.elem[i]+L.elem[L.length-i-1];\n L.elem[L.length-i-1]=L.elem[i]-L.elem[L.length-i-1];\n L.elem[i]=L.elem[i]-L.elem[L.length-i-1];\n }\n}"
},
{
"id": "DC02PE45",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid Union(SqList &La, List Lb) \n{ \n ElemType e;\n int len;\n len=ListLength_Sq(Lb);\n for(int i=0;i<len;i++)\n {\n GetElem_Sq(Lb,i+1,e);\n if(Search_Sq(La,e)==-1)\n Append_Sq(La,e);\n }\n}"
},
{
"id": "DC02PE53",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus StackEmpty_L(LStack S) \n{ \n if(S==NULL)\n return TRUE; \n return FALSE;\n}"
},
{
"id": "DC02PE55",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus GetTop_L(LStack S, ElemType &e) \n{ \n if(S==NULL)\n return ERROR;\n\n e=S->data;\n return OK;\n}"
},
{
"id": "DC02PE61",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus QueueEmpty_LQ(LQueue Q)\n{ \n if(Q.front==nullptr)\n return TRUE;\n return FALSE;\n}"
},
{
"id": "DC02PE63",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint QueueLength_LQ(LQueue Q) \n{ \n if(Q.front==NULL)\n return 0;\n int count=0;\n QueuePtr p=Q.front;\n do{\n count++;\n }while(p=p->next);\n return count;\n}"
},
{
"id": "DC02PE68",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus InitCLQueue(CLQueue &rear) \n{\n //创建一个只有一个元素(头结点)的链表\n CLQueue p=(CLQueue)malloc(sizeof(CLQNode));\n if (p == NULL)\n {\n return ERROR;\n }\n\n p->next=p;\n p->data=0;\n rear=p;\n\n return OK;\n} \n\nStatus EnCLQueue(CLQueue &rear, ElemType x)\n{ \n CLQueue p=(CLQueue)malloc(sizeof(CLQNode));\n if (p == NULL)\n {\n return ERROR;\n }\n \n p->data=x;\n //插入到链表中\n p->next=rear->next;\n rear->next=p;\n //修改队尾节点指针\n rear=p;\n \n return OK;\n}\n\nStatus DeCLQueue(CLQueue &rear, ElemType &x)\n{ \n if(rear->next==rear)//若相等说明只有一个元素(头节点)\n return ERROR;\n CLQueue pBegin=rear->next;//指向头节点\n x=pBegin->next->data;\n pBegin->next=pBegin->next->next;\n return OK;\n}"
},
{
"id": "DC02PE71",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus ListEmpty_L(LinkList L) \n{ \n if(L->next==nullptr)\n return TRUE;\n return FALSE;\n}"
},
{
"id": "DC02PE73",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus DestroyList_L(LinkList &L) \n{ \n\t LinkList p, pTemp;\n\t //p指向头结点\n\t p = L;\n\t while (p != NULL)//遍历一个一个删除结点\n\t {\n\t\t pTemp = p->next;//pTemp指向下一个\n\t\t free(p); //释放掉结点\n\t\t p = pTemp;//p指向新的头结点\n\t }\n\t //指针赋值NULL,防止变成野指针\n\t L = nullptr;\n return OK;\n}"
},
{
"id": "DC02PE75",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus ClearList_L(LinkList &L)\n{ \n if(L==NULL)\n return ERROR;\n LinkList p,pTemp;\n p=L->next;\n while(p != nullptr)\n {\n pTemp = p->next;\n free(p);\n p=pTemp;\n }\n L->next=NULL;\n return OK;\n}"
},
{
"id": "DC02PE77",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint ListLength_L(LinkList L) \n{\n if(L==nullptr)\n return -1;\n int count=0;\n LinkList p=L;\n while(p->next!=nullptr)\n {\n count++;\n p=p->next;\n }\n \n return count;\n}"
},
{
"id": "DC02PE82",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Insert_L(LinkList L, int i, ElemType e) \n{ \n if(i<1)\n return ERROR;\n \n LinkList p,pPrev;\n p=L;\n for(int k=0;k<i;k++)\n {\n if(p==nullptr)//这里也包括对头结点为NULL的判断\n return ERROR;\n pPrev=p;\n p=p->next;\n }\n //结束时p指向i+1位置,pPrev指向i位置\n LinkList pNew=(LinkList)malloc(sizeof(LNode));\n pNew->data=e;\n pNew->next=p;\n pPrev->next=pNew;\n\n return OK;\n}"
},
{
"id": "DC02PE84",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Delete_L(LinkList L, int i, ElemType &e) \n{ \n //传入数据有误\n if(L==NULL||i<1)\n return ERROR;\n \n LinkList p,pPrev;\n p=L;\n for(int k=0;k<i;k++)\n {\n pPrev=p;\n p=p->next;\n if(p==nullptr)\n return ERROR;//说明没有第i个元素\n }\n //结束时p指向i位置,pPrev指向i-1位置\n e=p->data;\n pPrev->next=p->next;\n free(p);\n return OK;\n}"
},
{
"id": "DC02PE86",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Split_L(LinkList L, LinkList &Li, int i)\n{ \n //传入数据有误\n if(L==NULL||i<1)\n {\n Li=nullptr;\n return ERROR;\n }\n \n //1.移除\n LinkList p,pPrev;\n p=L;\n for(int k=0;k<i;k++)\n {\n pPrev=p;\n p=p->next;\n if(p==nullptr)//说明没有第i个元素\n {\n Li=nullptr;\n return ERROR;\n }\n }\n //结束时p指向i位置,pPrev指向i-1位置\n pPrev->next=0;\n\n \n //2.构成带头结点链表Li\n LinkList pLi=(LinkList)malloc(sizeof(LNode));\n pLi->data=NULL;\n pLi->next=p;\n Li=pLi;\n return OK;\n \n}"
},
{
"id": "DC02PE88",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Cut_L(LinkList L, int i)\n{\n //传入数据有误\n if(L==NULL||i<1)\n return ERROR;\n \n LinkList p,pPrev;\n p=L;\n for(int k=0;k<i;k++)\n {\n pPrev=p;\n p=p->next;\n if(p==nullptr)//说明没有第i个元素\n return ERROR;\n }\n //结束时p指向i位置,pPrev指向i-1位置\n pPrev->next=0;//删除单链表L后面的所有元素\n\n //以下是第i个元素存在时的情况\n do{\n pPrev=p;\n p=p->next;\n free(pPrev);\n }while(p);\n\n return OK;\n}"
},
{
"id": "DC02PE90",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus DeleteX_L(LinkList L, ElemType x) \n{ \n //传参有误\n if(L==nullptr)\n return ERROR;\n \n int count=0;//实际删除元素个数\n LinkList p,pPrev,pNext;\n \n pPrev=L;\n p=L->next;\n while(p)\n {\n if(p->data==x)\n {\n pPrev->next=p->next;\n free(p);//释放本结点\n count++;\n p=pPrev;\n }\n pPrev=p;\n p=p->next;\n }//退出循环时,p指向NULL,pPrev指向尾结点\n\n return count;\n}"
},
{
"id": "DC02PE91",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus DeleteSome_L(LinkList L, ElemType x) \n{\n //传参有误\n if(L==nullptr)\n return ERROR;\n \n int count=0;//存放实际删除元素个数\n LinkList p,pPrev,pNext;\n \n pPrev=L;\n p=L->next;\n while(p)\n {\n if(p->data<x)\n {\n pPrev->next=p->next;\n free(p);//释放本结点\n count++;\n p=pPrev;\n }\n pPrev=p;\n p=p->next;\n }//退出循环时,p指向NULL,pPrev指向尾结点\n\n return count;\n}"
},
{
"id": "DC03PE03",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid InsertSort(RcdSqList &L)\n{ \n //直接插入排序,从小到大\n\n //在1号位到length号位都有数据,这样就有length个数据\n for(int i=2;i<L.length+1;i++)//进行length-1次插入,因为默认第一个直接成为一个有序数列\n {\n L.rcd[L.length+1].key=L.rcd[i].key;//准备将第i个数值进行插入,设置哨兵\n int j=i-1;\n while(L.rcd[L.length+1].key<L.rcd[j].key)//直到哨兵的数值大于或等于rcd[j]\n {\n L.rcd[j+1].key=L.rcd[j].key;\n j--;\n }\n L.rcd[j+1].key=L.rcd[L.length+1].key;\n }\n}"
},
{
"id": "DC03PE06",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid BubbleSort(RcdSqList &L) { \n/* 元素比较和交换必须调用以下比较函数和交换函数:*/\n/* Status LT(RedType a, RedType b); 比较:\"<\" */\n/* Status GT(RedType a, RedType b); 比较:\">\" */\n/* void Swap(RedType &a, RedType &b); 交换 */\n int i,j;\n int change=L.length;\n int tChange;//change的tmp\n\n i=1;\n while(i<L.length)\n {\n tChange=0;\n for(j=1;j<change;j++)//for(j=1;j<L.length-i+1;j++)\n {\n if(GT(L.rcd[j], L.rcd[j+1]))\n {\n Swap(L.rcd[j], L.rcd[j+1]);\n tChange=j;\n }\n }//执行完这个内循环后,tChange=进行最后一次交换记录(j+1)的前一个记录(j)位置\n //说明从第tChange+1一直到length的数据已经排好了\n //本来是只排好一个在change位置的数据,此时tChange=change-1。\n //如果数据比较好,会比预计排好的多,tChange就会小于change-1\n //就是默认时进行一轮内循环后排序好change-tChange=1个。\n //现在数据好一些,现在进行一轮内循环后排序好change-tChange>1个。\n i+=change-tChange;\n change=tChange;//使下一次内循环对从第1到tChange的数据进行比较、排序\n }\n \n \n //以下是优化前的冒泡排序\n /*\n int i,j;\n for(i=1;i<L.length;i++)\n {\n for(j=1;j<L.length-i+1;j++)\n {\n if(GT(L.rcd[j], L.rcd[j+1]))\n {\n Swap(L.rcd[j], L.rcd[j+1]);\n }\n }\n }\n */\n}"
},
{
"id": "DC03PE23",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid CountSort(RcdSqList &L) // 请自行定义计数数组c,用作排序辅助\n{ \n //条件:关键字不相同,所以c的元素不会有重复的数字\n //计数排序\n int c[L.length+1]={0};\n RcdType a[L.length+1]={0};\n \n //让你找一个记录L.rcd[i],有几个小于L.rcd[i]的数,将L.rcd遍历就行\n for(int i=1;i<=L.length;i++)\n {\n for(int j=1;j<=L.length;j++)\n {\n if(L.rcd[i].key>L.rcd[j].key)//不用统计等于时的数据\n c[i]++;\n }\n }\n //现在已经生成了c\n //索引相同时,对于c和L.rcd两组数据,有这个关系:L.rcd[i]是第c[i]+1小的数据。\n //比如c[i]=0时,对应L.rcd[i]就是从小到大排序后的第1个数据。\n for(int i=1;i<=L.length;i++)\n {\n a[i]=L.rcd[i];\n }\n \n for(int i=1;i<=L.length;i++)\n {\n L.rcd[c[i]+1]=a[i];\n }\n}"
},
{
"id": "DC04PE04",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid PrintKeys(HashTable ht, void(*print)(StrKeyType)){\n int index, tempIndex;\n for (char c = 'A' ; c <= 'Z' ; c++) {//按字母顺序从A到Z\n index = (c - 'A') % ht.size;//哈希函数H(key)为关键字的首字母在字母表中的序号,用除留余数法\n tempIndex = index;\n while(ht.rcd[index].tag != UNSUCCESS)//情况为SUCCESS或DUPLICATE时进入循环\n {\n if(ht.rcd[index].tag == SUCCESS && ht.rcd[index].key[0] == c)\n print(ht.rcd[index].key);//输出关键字\n index = (index + 1) % ht.size;//线性探测\n if(tempIndex==index)\n break;\n }\n }\n}"
},
{
"id": "DC04PE15",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint BuildHashTab(ChainHashTab &H, int n, HKeyType es[])\n{ \n int index;//在哈希表中的索引\n int i=0;//遍历es中的记录\n while(i<n)\n {\n //1.先创建和初始化结点\n HLink pNode = (HLink)malloc(sizeof(HNode));\n //if(pNode==nullptr)\n // return EOVERFLOW;\n pNode->data = es[i];\n pNode->next = nullptr;\n //2.找到关键字对应的索引位置\n index = Hash(H, es[i]);\n //3.判断Hash表相应位置是否已经有相同关键字存在\n HLink p=H.rcd[index];\n if(p!=nullptr)\n {\n do\n {\n if(p->data==es[i])//已经存在此关键字\n {\n goto nloop;\n }\n }while(Collision(H, p)==SUCCESS);\n }\n //4.若没有该关键字,则放入该关键字\n pNode->next=H.rcd[index];\n H.rcd[index]=pNode;\nnloop: i++;\n }\n return SUCCESS;\n}"
},
{
"id": "DC05PE04",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint G(int m, int n) \n{ \n if(m<0||n<0)\n return -1;\n if(m==0)\n return 0;\n return G(m-1,2*n)+n;\n}"
},
{
"id": "DC05PE05",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint F(int n) \n{ \n if(n<0)\n return -1;\n if(n==0)\n return 1;\n return n*F(n/2);\n}"
},
{
"id": "DC05PE06",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nfloat Sqrt(float A, float p, float e) \n{ \n if(abs(p*p-A)<e)\n return p;\n return Sqrt(A,(p+A/p)/2,e);\n}"
},
{
"id": "DC05PE07",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint Akm(int m, int n) \n{ \n if(m<0||n<0)\n return -1;\n if(m==0)\n return n+1;\n if(m!=0&&n==0)\n return Akm(m-1,1);\n return Akm(m-1,Akm(m,n-1));\n}"
},
{
"id": "DC05PE15",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint F(int n) \n{ \n if(n<0)\n return -1;//ERROR ARGUMENT\n if(n==0)\n return 1;\n \n //F(n)=n*F(n/2)\n //F(1)=1*F(0)=1*1=1\n //F(8)=8*F(4)=8*4*F(2)=8*4*2*F(1)=8*4*2*1*F(0)=8*4*2*1*1\n int result=n;//result当作F(n)\n while(n/=2)\n {\n result*=n;\n }\n return result;\n}"
},
{
"id": "DC05PE16",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nfloat Sqrt(float A, float p, float e) \n{\n if(p==0)\n return ERROR;\n while(abs(p*p-A)>=e)\n {\n p=(p+A/p)/2;\n }\n return p;\n //牛顿迭代法:https://blog.csdn.net/u010947534/article/details/87874019\n}"
},
{
"id": "DC05PE20",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid ChangeColor(GTYPE g, int m, int n, char c, int i0, int j0) \n{ \n int tmp=g[i0][j0];//原来的颜色\n g[i0][j0]=c;//新的颜色\n\n if(i0-1>=0 && g[i0-1][j0]==tmp) ChangeColor(g, m, n, c, i0-1, j0);\n if(i0+1<=m && g[i0+1][j0]==tmp) ChangeColor(g, m, n, c, i0+1, j0);\n if(j0-1>=0 && g[i0][j0-1]==tmp) ChangeColor(g, m, n, c, i0, j0-1);\n if(j0+1<=n && g[i0][j0+1]==tmp) ChangeColor(g, m, n, c, i0, j0+1);\n return;\n}"
},
{
"id": "DC05PE30",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint GListDepth(GList ls) \n{ \n int h1,h2;\n if(ls==nullptr)\n return 1;//空表,深度为1\n if(ls->tag==ATOM)\n return 0;//是一个原子,深度为0\n h1=GListDepth(ls->un.ptr.hp)+1;//表头的深度加1\n h2=GListDepth(ls->un.ptr.tp);//表尾的深度不需要加1,表尾的深度与原表相同\n return h1>=h2?h1:h2;\n}"
},
{
"id": "DC05PE32",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Equal(GList A, GList B) \n{ \n if(A==nullptr || B==nullptr )\n {\n if(A==nullptr && B==nullptr) \n return TRUE;\n else return FALSE;\n }\n \n if(A->tag==ATOM || B->tag==ATOM)\n {\n if(A->tag==ATOM && B->tag==ATOM && A->un.atom==B->un.atom) \n return TRUE;\n //要先A->tag==ATOM、B->tag==ATOM都满足才能进行A->un.atom==B->un.atom的判断,否则可能会非法访问内存\n else return FALSE;\n }\n \n int r1 = Equal(A->un.ptr.hp,B->un.ptr.hp);\n int r2 = Equal(A->un.ptr.tp,B->un.ptr.tp);\n \n return r1&&r2;\n}"
},
{
"id": "DC05PE33",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid OutAtom(GList A, int layer, void(*Out2)(char, int)) \n{ \n //layer一开始是0\n //若广义表里只有一个原子A,这时A所在层数为0\n if(A==nullptr)\n return;\n \n if(A->tag==ATOM)\n {\n Out2(A->un.atom, layer);\n return;\n }\n \n OutAtom(A->un.ptr.hp, layer+1, Out2);\n OutAtom(A->un.ptr.tp, layer, Out2);\n}"
},
{
"id": "DC06PE01",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint commonAncestor(SqBiTree T, int i, int j) \n{ \n if(i>T.lastIndex || j>T.lastIndex || i<2 || j<2)//1号位没有祖先,所以至少要是2号位\n return 0;\n \n i/=2;//找i的父亲\n j/=2;//找j的父亲\n \n while(i!=j)\n {\n if(i>=j)\n i/=2;\n else\n j/=2;\n }\n return i;\n}"
},
{
"id": "DC06PE02",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus is_Desendant(SqBiTree T, int u, int v) \n{ \n //v结点是否是u结点的子孙\n if(u<1 || u>T.lastIndex || v<1 || v>T.lastIndex || v<=u)\n return FALSE;\n \n while(v>u)\n {\n v/=2;\n }\n if(u==v)\n return TRUE;\n return FALSE;\n}"
},
{
"id": "DC06PE06",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Similar(BiTree T1, BiTree T2) \n{ \n if(T1==NULL || T2==NULL)\n {\n if(T1==NULL && T2==NULL)\n return TRUE;\n return FALSE;\n }\n int r1=Similar(T1->lchild, T2->lchild);\n int r2=Similar(T1->rchild, T2->rchild);\n return r1&&r2;\n /*\n 比较两个节点都为空就相等、有一个为空,另一个非空则不相等。\n 最后递归判断两个数的左子树和右子树是否相等。\n */\n}"
},
{
"id": "DC06PE11",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nTElemType PreOrderFindK(BiTree T, int &k) \n{\n TElemType result = '#'; \n if(T == NULL)\n return '#';\n if(k==1)\n return T->data;\n k--;\n if(T->lchild!=nullptr)\n result = PreOrderFindK(T->lchild, k);\n if(result == '#' && T->rchild!=nullptr)\n result = PreOrderFindK(T->rchild, k);\n return result;\n}\nTElemType PreOrderK(BiTree T, int k) \n{\n return PreOrderFindK(T,k);\n}"
},
{
"id": "DC06PE12",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint Leaves(BiTree T) \n{ \n if (T==NULL)\n return 0;\n if(T->lchild==NULL && T->rchild==NULL)\n return 1;\n int r1 = Leaves(T->lchild);\n int r2 = Leaves(T->rchild);\n return r1+r2;\n}"
},
{
"id": "DC06PE21",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid PreOrder(BiTree T, Status (*visit)(TElemType))\n{ \n Stack S;\n InitStack(S);\n BiTree p=T;\n \n while (StackEmpty(S)!=TRUE || p!=NULL)//栈非空或p非空时\n {\n while(p)\n {\n visit(p->data);\n Push(S, p);\n p = p->lchild;\n }\n if (!StackEmpty(S))\n {\n Pop(S,p);\n p = p->rchild;\n }\n }\n return;\n}"
},
{
"id": "DC06PE23",
"code": "#include \"allinclude.h\" //DO NOT edit this line\n//参考:https://blog.csdn.net/wayne_b/article/details/46276429\n//tag: 0表示刚遍历完该节点的左子树,需要遍历右子树;1表示已经遍历完该节点左右子树\nvoid GoFar(BiTree &T,Stack &S, Status (*visit)(TElemType))\n{\n SElemType tmp; \n while(T->lchild!=NULL || T->rchild!=NULL)\n {\n tmp.ptr = T;\n if(T->lchild != NULL && T->rchild !=NULL) //还有右孩子,仍要继续遍历\n { \n tmp.tag = 0;\n T = T->lchild;\n }\n else if(T->lchild != NULL && T->rchild == NULL)\n {\n tmp.tag = 1;\n T = T->lchild;\n }\n else if(T->rchild != NULL) //没有左孩子只有右孩子就深入右孩子\n {\n tmp.tag = 1;\n T = T->rchild; \n }\n Push(S,tmp); //T节点入栈\n }\n visit(T->data);\n return;\n}\nvoid PostOrder(BiTree T, Status (*visit)(TElemType))\n{\n if(T == NULL) \n return; \n Stack S; \n InitStack(S); \n SElemType e;\n BiTree p = T;\n \n GoFar(p, S, visit); //调用函数深入二叉树\n \n SElemType tmp;\n while(p != NULL && StackEmpty(S)!=TRUE)\n {\n Pop(S,tmp); //祖先节点出栈\n p = tmp.ptr;\n if(tmp.tag == 0) //若刚遍历完该节点的左孩子\n { \n tmp.tag = 1; //有的话tag致1入栈\n Push(S, tmp);\n p = p->rchild;\n GoFar(p,S, visit); //且深入它的右子树继续遍历\n }\n else if(tmp.tag==1)\n {\n visit(p->data); //若已遍历完左右子树就访问自己\n }\n }\n}"
},
{
"id": "DC06PE27",
"code": "#include \"allinclude.h\" //DO NOT edit this line\n//参考:https://blog.csdn.net/qq1094417747/article/details/52831479\nvoid InOrder(TriTree PT, Status (*visit)(TElemType)) \n{ \n TriTree p = PT, pChild;\n \n while(p!=NULL) \n { \n if(p->lchild!=NULL) \n {\n p = p->lchild;\n continue;\n }\n visit(p->data); \n if (p->rchild!=NULL) \n { \n p =p->rchild; \n continue;\n } \n pChild = p; \n p = p->parent; \n while (p && (p->lchild != pChild ||!p->rchild)) //若其不是从左子树回溯来的,或左结点的父亲并没有右孩子\n { \n if (p->lchild == pChild) //若左结点的父亲并没有右孩子 \n visit(p->data); //直接访问父亲(不用转到右孩子) \n pChild = p; //父亲已被访问,故返回上一级\n p = p->parent; //该while循环沿双亲链一直查找,若无右孩子则访问,直至找到第一个有右孩子的结点为止(但不访问该结点,留给下步if语句访问)\n } \n if (p) \n { //访问父亲,并转到右孩子(经上步while处理,可以确定此时p有右孩子)\n visit(p->data);\n p = p->rchild; \n } \n } \n}"
},
{
"id": "DC06PE29",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid PostOrder(TriTree T, Status (*visit)(TElemType)) \n{ \n TriTree p = T;\n\n while (p != NULL)\n {\n if (p->mark == 0)\n {\n p->mark++;\n while (p->lchild != NULL)\n {\n p = p->lchild;\n p->mark++;\n }\n continue;\n }\n if (p->mark == 1)\n {\n p->mark++;\n if (p->rchild != NULL)\n p = p->rchild;\n continue;\n }\n if (p->mark == 2)\n {\n visit(p->data);\n p = p->parent;\n }\n }\n}"
},
{
"id": "DC06PE30",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus Similar(BiTree t1, BiTree t2) \n{ \n if(t1==NULL || t2==NULL)\n {\n if(t1==NULL && t2==NULL)\n return TRUE;\n return FALSE;\n }\n int r1=Similar(t1->lchild, t2->lchild);\n int r2=Similar(t1->rchild, t2->rchild);\n return r1&&r2;\n}"
},
{
"id": "DC06PE31",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid PreOrder(BiTree bt, void (*visit)(TElemType)) \n{\n SqStack2 S;\n InitStack_Sq2(S);\n \n BiTree p = bt;\n while(StackEmpty_Sq2(S)!=TRUE || p!=NULL)\n {\n while(p!=NULL)\n {\n visit(p->data);\n Push_Sq2(S, p); \n p=p->lchild;\n }\n \n if(!StackEmpty_Sq2(S))\n {\n Pop_Sq2(S, p);\n p=p->rchild;\n }\n }\n return;\n}"
},
{
"id": "DC06PE32",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid PostOrder(BiTree bt, void (*visit)(TElemType))\n{\n if(bt == NULL) \n return;\n SqStack2 S; \n InitStack_Sq2(S); \n SElemType e;\n BiTree p = bt;\n \n e.ptr=p;\n e.tag=0;//e.tag=p->mark;\n Push_Sq2(S,e);\n while(!StackEmpty_Sq2(S))\n {\n Pop_Sq2(S,e);\n if(e.tag==0)\n { \n e.tag=1;\n Push_Sq2(S,e); \n \n if(e.ptr->lchild!=NULL)\n {\n e.ptr=e.ptr->lchild;\n e.tag=0;\n Push_Sq2(S,e);\n } \n continue;\n }\n if(e.tag==1)\n {\n e.tag=2;\n Push_Sq2(S,e); \n \n if(e.ptr->rchild!=NULL)\n {\n e.ptr=e.ptr->rchild;\n e.tag=0;\n Push_Sq2(S,e);\n } \n continue;\n }\n if(e.tag==2)\n {\n visit(e.ptr->data); \n } \n }\n}"
},
{
"id": "DC06PE33",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid ExchangeSubTree(BiTree &T)\n{ \n if(T!=NULL)\n {\n BiTree tempT=T->lchild;\n T->lchild=T->rchild;\n T->rchild=tempT;\n ExchangeSubTree(T->lchild);\n ExchangeSubTree(T->rchild);\n }\n}"
},
{
"id": "DC06PE34",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid PostOrder(TriTree bt, void (*visit)(TElemType))\n/* 不使用栈,非递归后序遍历二叉树bt, */\n/* 对每个结点的元素域data调用函数visit */\n{\n TriTree p = bt;\n\n while (p != NULL)\n {\n if (p->mark == 0)\n {\n p->mark++;\n while (p->lchild != NULL)\n {\n p = p->lchild;\n p->mark++;\n }\n continue;\n }\n if (p->mark == 1)\n {\n p->mark++;\n if (p->rchild != NULL)\n p = p->rchild;\n continue;\n }\n if (p->mark == 2)\n {\n visit(p->data);\n p = p->parent;\n }\n }\n}"
},
{
"id": "DC06PE35",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid InOrder(TriTree PT, void (*visit)(TElemType))\n/* 不使用栈,非递归中序遍历二叉树bt, */\n/* 对每个结点的元素域data调用函数visit */\n{ \n TriTree p = PT;\n\n while (p != NULL)\n {\n if (p->mark == 0)\n {\n p->mark++;\n while (p->lchild != NULL)\n {\n p = p->lchild;\n p->mark++;\n }\n continue;\n }\n if (p->mark == 1)\n {\n p->mark++;\n visit(p->data);\n if (p->rchild != NULL)\n p = p->rchild;\n continue;\n }\n if (p->mark == 2)\n { \n p = p->parent;\n }\n }\n}"
},
{
"id": "DC06PE36",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nBiTNode* getLastNode(BiTree T)\n/* 求完全二叉树的最后一层的最后一个结点 */\n{ \n if(T==NULL || (T->lchild==NULL&&T->rchild==NULL))\n return T;\n //求二叉树深度\n int dep=0;\n BiTree curNode = T;\n while(curNode!=NULL)\n {\n dep++;\n curNode = curNode->lchild;\n }\n \n\n int level = 0;\n BiTree p = T;\n \twhile(p)//控制p下一步往右还是往左走\n \t{\n \t\tlevel++;//level: 当前的层数\n \t\tif(level == dep) break;//当前是最后一层,退出。\n \t\tcurNode = p;\n \t\t\n \t\tif(curNode->rchild!=NULL)//当前结点的右孩子是否存在\n \t\t{\n \t\t BiTree pPar = curNode;//pPar: 当前节点的父节点\n \t\t curNode = curNode -> rchild;\n \t\t int tmpDep = level + 1;//tmp:当前深度。往右走之后深度为level加一\n \t\t \n \t\t\twhile(curNode->lchild)//找到右孩子后一直往左走\n \t\t\t{\n \t\t\t\ttmpDep++;\n \t\t\t\tpPar = curNode;\n \t\t\t\tcurNode = curNode->lchild;\n \t\t\t}\n \t\t\t//curNode: 当前找到的目标结点\n \t\t\t\n \t\t\tif(tmpDep < dep)//说明p往右走不对。往左走\n \t\t\t p = p->lchild; \t\t\t\n \t\t\telse if(tmpDep == dep && (pPar->rchild != NULL && pPar->rchild != curNode))\n \t\t\t p = p->rchild;\n \t\t\telse if(tmpDep == dep && (pPar->rchild == NULL || pPar->rchild == curNode))\n \t\t\t return curNode;\n \t\t}\n \t\telse p = p->lchild;//右孩子不存在,直接往左走\n \t}\n return p;\n}"
},
{
"id": "DC06PE37",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint BiTreeDepth(BiTree T)\n{\n if(T==NULL)\n return 0;\n int r1 = BiTreeDepth(T->lchild);\n int r2 = BiTreeDepth(T->rchild);\n return 1 + (r1 > r2 ? r1 : r2);\n}\n\nint Depthx(BiTree T, TElemType x)\n{ \n if(T==NULL)\n return 0;\n if(T->data==x)\n return BiTreeDepth(T);\n int r1=Depthx(T->lchild,x);\n int r2=Depthx(T->rchild,x);\n return r1>r2?r1:r2;\n}"
},
{
"id": "DC06PE40",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid NodesDel(BiTree &bt)\n{\n if(bt==NULL)\n return;\n NodesDel(bt->lchild);\n NodesDel(bt->rchild);\n free(bt);\n return;\n}\nvoid ReleaseX(BiTree &bt, char x)\n{ \n BiTree p=NULL;\n if (bt == NULL)\n return;\n if(bt->data==x)\n {\n p = bt;\n bt = NULL;\n NodesDel(p);\n }\n \n if(bt!=NULL)\n {\n ReleaseX(bt->lchild, x);\n }\n if(bt!=NULL)\n {\n ReleaseX(bt->rchild, x);\n }\n return;\n}"
},
{
"id": "DC06PE43",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid CopyBiTree(BiTree T, BiTree &TT) \n{ \n if(T==NULL)\n return;\n \n BiTree p = (BiTree)malloc(sizeof(BiTNode));\n p->data = T->data;\n p->lchild=T->lchild;\n p->rchild=T->rchild;\n TT = p;\n CopyBiTree(T->lchild,p->lchild);\n CopyBiTree(T->rchild,p->rchild);\n}"
},
{
"id": "DC06PE44",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint BiTreeDepth(BiTree T)\n{\n int depthLeft, depthRight;\n if(T==NULL)\n return 0;\n else\n {\n depthLeft = BiTreeDepth(T->lchild);\n depthRight = BiTreeDepth(T->rchild);\n return 1+(depthLeft>depthRight?depthLeft:depthRight);\n }\n}\nint Depthx(BiTree T, TElemType x)\n{ \n if(T==NULL)\n return 0;\n if(T->data==x)\n return BiTreeDepth(T);\n int r1=Depthx(T->lchild,x);\n int r2=Depthx(T->rchild,x);\n return r1>r2?r1:r2;\n}"
},
{
"id": "DC06PE45",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid NodesDel(BiTree &bt)\n{\n if(bt==NULL)\n return;\n NodesDel(bt->lchild);\n NodesDel(bt->rchild);\n free(bt);\n return;\n}\nvoid ReleaseX(BiTree &bt, char x)\n{ \n BiTree p=NULL;\n if (bt == NULL)\n return;\n if(bt->data==x)\n {\n p = bt;\n bt = NULL;\n NodesDel(p);\n }\n \n if(bt!=NULL)\n {\n ReleaseX(bt->lchild, x);\n }\n if(bt!=NULL)\n {\n ReleaseX(bt->rchild, x);\n }\n return;\n}"
},
{
"id": "DC06PE46",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid CopyBiTree(BiTree T, BiTree &TT)\n{ \n if(T==NULL)\n {\n TT==NULL;\n return;\n }\n BiTree p1 = T;\n\n //复制根结点\n BiTree p2 = (BiTree)malloc(sizeof(BiTNode));\n memset(p2, 0, sizeof(BiTNode));\n p2->data = p1->data;\n TT = p2;\n \n LQueue Q,Q2;\n InitQueue_LQ(Q);\n InitQueue_LQ(Q2);\n \n EnQueue_LQ(Q,p1);\n EnQueue_LQ(Q2,p2);\n while(!QueueEmpty_LQ(Q))\n {\n DeQueue_LQ(Q,p1);\n DeQueue_LQ(Q2,p2);\n if(p1->lchild!=NULL)\n {\n BiTree pNode = (BiTree)malloc(sizeof(BiTNode));\n memset(pNode, 0, sizeof(BiTNode));\n p2->lchild = pNode;\n p2->lchild->data = p1->lchild->data;\n EnQueue_LQ(Q,p1->lchild);\n EnQueue_LQ(Q2,p2->lchild);\n }\n if(p1->rchild!=NULL)\n {\n BiTree pNode = (BiTree)malloc(sizeof(BiTNode));\n memset(pNode, 0, sizeof(BiTNode));\n p2->rchild = pNode;\n p2->rchild->data = p1->rchild->data;\n EnQueue_LQ(Q,p1->rchild);\n EnQueue_LQ(Q2,p2->rchild);\n }\n }\n}"
},
{
"id": "DC06PE47",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid LevelOrder(BiTree bt, char *ss)\n{ \n if(bt == NULL)\n return;\n BiTree p =bt;\n char sp[2]={0};\n LQueue Q;\n InitQueue_LQ(Q);\n \n EnQueue_LQ(Q,p);\n while(!QueueEmpty_LQ(Q))\n {\n DeQueue_LQ(Q,p);\n sprintf(sp,\"%c\",p->data);\n strcat(ss,sp);\n if(p->lchild!=NULL)\n {\n EnQueue_LQ(Q,p->lchild);\n }\n if(p->rchild!=NULL)\n {\n EnQueue_LQ(Q,p->rchild);\n }\n }\n/* int len = strlen(ss);\n ss[len]={0};*/ \n}"
},
{
"id": "DC06PE48",
"code": "#include \"allinclude.h\" //DO NOT edit this line\n//参考:https://blog.csdn.net/wayne_b/article/details/46276429\nbool FindPath(BiTree T, TElemType c, SqStack2& S)\n{\n if(T==NULL)\n return FALSE;\n if(T->data == c)\n return TRUE;\n SElemType tmp;\n tmp.tag = 0;\n if(FindPath(T->lchild, c, S)|| FindPath(T->rchild, c, S))\n {\n tmp.ptr = T;\n Push_Sq2(S, tmp);\n }\n else return FALSE;\n return TRUE;\n}\n\nBiTree CommAncestor(BiTree root, TElemType c1, TElemType c2)\n{\n if(root == NULL || c1==root->data || c2==root->data) \n return NULL; \n \n SqStack2 S1, S2; \n InitStack_Sq2(S1); \n InitStack_Sq2(S2); \n \n if(FindPath(root, c1, S1)==FALSE)\n return NULL;\n if(FindPath(root, c2, S2)==FALSE)\n return NULL; \n \n SElemType par1, par2, par;\n do{\n par = par1;\n Pop_Sq2(S1, par1);\n Pop_Sq2(S2, par2);\n }while(StackEmpty_Sq2(S1)!=TRUE && StackEmpty_Sq2(S2)!=TRUE && par1.ptr==par2.ptr);\n if(par1.ptr==par2.ptr)\n return par1.ptr;\n else return par.ptr;\n}"
},
{
"id": "DC06PE49",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus CompleteBiTree(BiTree bt)\n{ \n if(bt == NULL)\n return TRUE;\n \n BiTree p = bt;\n LQueue Q;\n InitQueue_LQ(Q);\n while(p!=NULL)//一层一层遍历,知道遇到第一个NULL\n {\n EnQueue_LQ(Q, p->lchild);\n EnQueue_LQ(Q, p->rchild);\n DeQueue_LQ(Q, p);\n }\n while(!QueueEmpty_LQ(Q))//遇到NULL后,队列里都要是NULL\n {\n DeQueue_LQ(Q, p);\n if(p!=NULL)\n {\n if(p->data!=NULL)\n return FALSE;\n }\n }\n return TRUE;\n}"
},
{
"id": "DC06PE50",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus BTEqual(BiTree T1, BiTree T2)\n{ \n if(T1==NULL||T2==NULL)\n {\n if(T1==NULL && T2==NULL)\n return TRUE;\n return FALSE;\n }\n else if(T1->data==T2->data)\n {\n return TRUE;\n }\n else \n {\n return FALSE;\n }\n Status r1 = BTEqual(T1->lchild,T2->lchild);\n Status r2 = BTEqual(T1->lchild,T2->rchild);\n return r1&&r2;\n}"
},
{
"id": "DC06PE51",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid Degree1(BiTree T,int &count)\n{ \n //一个结点的度是这个结点含有子树的个数\n if(T==NULL)\n return;\n if(T->lchild!=NULL || T->rchild!=NULL)\n {\n if(T->lchild!=NULL&&T->rchild!=NULL)\n {\n ;\n }\n else{\n count++;\n }\n }\n Degree1(T->lchild,count);\n Degree1(T->rchild,count);\n return;\n}"
},
{
"id": "DC06PE52",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid NodesCount(BiTree T, int& count)\n{\n //分支结点:一个二叉树中度不为0的结点\n if(T==NULL)\n return;\n if(T->lchild!=NULL || T->rchild!=NULL)\n {\n if(T->lchild!=NULL && T->rchild!=NULL)\n ;\n count++;\n }\n NodesCount(T->lchild,count);\n NodesCount(T->rchild,count);\n}\nint BranchNodes(BiTree T)\n{ \n int count=0;\n NodesCount(T, count);\n return count;\n}"
},
{
"id": "DC06PE53",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint LevelSum(BiTree T)\n{ \n int count = 0;\n if(T==NULL)\n return count;\n count++;\n LQueue Q;\n InitQueue_LQ(Q);\n BiTree p = T;\n \n EnQueue_LQ(Q,p);\n do\n {\n DeQueue_LQ(Q,p);\n if(p->lchild!=NULL)\n {\n count++;\n EnQueue_LQ(Q,p->lchild);\n }\n if(p->rchild!=NULL)\n {\n count++;\n EnQueue_LQ(Q,p->rchild);\n }\n }while(!QueueEmpty_LQ(Q));\n \n return count;\n}"
},
{
"id": "DC06PE54",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid ChangeTree(BiTree &T)\n{ \n if(T==NULL)\n return;\n if(T->lchild==NULL && T->rchild !=NULL)\n {\n T->lchild=T->rchild;\n T->rchild=NULL;\n }\n ChangeTree(T->lchild);\n ChangeTree(T->rchild);\n}"
},
{
"id": "DC06PE55",
"code": "#include \"allinclude.h\" //DO NOT edit this line\n//参考:https://blog.csdn.net/u013709443/article/details/81212915\nint BiTreeDepth(BiTree T)\n{\n if(T==NULL)\n return 0;\n int r1 = BiTreeDepth(T->lchild);\n int r2 = BiTreeDepth(T->rchild);\n return 1 + (r1 > r2 ? r1 : r2);\n}\n\nint LevelWidth(BiTree T, int level)\n{\n\tif(T == NULL)\n\t return 0;//空,宽度为0\n\tif(level == 1)\n\t return 1;//宽度为1\n\tlevel = LevelWidth(T->lchild,level-1) + LevelWidth(T->rchild,level-1);\n\treturn level;\n}\n\nint Width(BiTree T)\n{\n if(T==NULL)\n\t return 0;\n\tint maxWid=0,wid;\n\tint dep = BiTreeDepth(T);\n\tfor(int i=1; i<=dep+1; i++)\n\t{\n\t wid = LevelWidth(T,i);\n\t if(wid > maxWid)\n\t {\n\t maxWid = wid;\n\t }\n\t}\n\treturn maxWid;\n}"
},
{
"id": "DC06PE56",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus SearchX(BiTree T, TElemType x)\n{ \n if(T==NULL)\n return ERROR;\n if(T->data==x)\n return TRUE;\n Status r1 = SearchX(T->lchild,x);\n Status r2 = SearchX(T->rchild,x);\n return r1||r2;\n}"
},
{
"id": "DC06PE57",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint NodeLevel(BiTree t, TElemType x)\n{ \n if(t==NULL)\n return -1;\n if(t->data==x)\n return 1;\n int r1 = NodeLevel(t->lchild,x);\n int r2 = NodeLevel(t->rchild,x);\n if(r1!=-1||r2!=-1)\n return (r1>r2)?r1+1:r2+1;\n return -1;\n}"
},
{
"id": "DC06PE58",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid NodesCount(BiTree T, int& count)\n{\n //一个子树所有结点\n if(T==NULL)\n return;\n count++;\n NodesCount(T->lchild,count);\n NodesCount(T->rchild,count);\n}\nint xSum(BiTree T, TElemType x)\n{ \n if(T==NULL)\n return 0;\n if(T->data==x)\n {\n int count=0;\n NodesCount(T, count);\n return count;\n }\n int r1 = xSum(T->lchild,x);\n int r2 = xSum(T->rchild,x);\n return r1 | r2;\n}"
},
{
"id": "DC06PE59",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid xLevel(BiTree T,TElemType x, bool &found, int &xlev)\n{ \n if(T==NULL)\n return;\n \n found=false;\n xlev++;\n if(T->data==x)\n {\n found = true;\n return;\n }\n\n int tmp=xlev;\n xLevel(T->lchild,x,found,xlev);\n if(found==0)\n {\n xlev= tmp;\n xLevel(T->rchild,x,found,xlev);\n }\n else return;\n}"
},
{
"id": "DC06PE60",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus RegularBiTree(BiTree T)\n{ \n if(T==NULL)\n return TRUE;\n if(T->lchild!=NULL||T->rchild!=NULL)\n {\n if(T->lchild!=NULL&&T->rchild!=NULL)\n ; \n else return FALSE;\n }\n Status r1 = RegularBiTree(T->lchild);\n Status r2 = RegularBiTree(T->rchild);\n return r1&&r2;\n}"
},
{
"id": "DC06PE61",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus SmallBiTree(BiTree T)\n{ \n if(T==NULL)\n return OK;\n Status r1=OK;\n Status r2=OK;\n if(T->lchild!=NULL && T->lchild->data >= T->data)\n {\n return ERROR;\n }\n if(T->rchild!=NULL && T->rchild->data >= T->data)\n {\n return ERROR;\n }\n r1=SmallBiTree(T->lchild);\n r2=SmallBiTree(T->rchild);\n return r1&&r2;\n}"
},
{
"id": "DC06PE62",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint Width(BiTree T)\n{\n if(T==NULL)\n return 0;\n \n LQueue Q;\n ElemType e;\n int maxWid=-1;\n int lcount;//上一层的节点数,宽度\n int count;//这一层的节点数,宽度\n InitQueue_LQ(Q);\n EnQueue_LQ(Q,T);\n lcount = 1;\n \n while(QueueEmpty_LQ(Q)!=TRUE)\n {\n count = 0;\n for(int i=0;i<lcount;i++)\n {\n DeQueue_LQ(Q, e);\n if(e->lchild!=NULL)\n {\n EnQueue_LQ(Q,e->lchild);\n count++;\n }\n if(e->rchild!=NULL)\n {\n EnQueue_LQ(Q,e->rchild);\n count++;\n }\n }\n if(count>maxWid)\n maxWid = count;\n lcount = count;\n }\n return maxWid;\n}"
},
{
"id": "DC06PE65",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus IsBSTree(BSTree T) \n{ \n if(T==NULL)\n return OK;\n Status r1 = OK;\n Status r2 = OK;\n if(T->lchild!=NULL)\n {\n if(T->data.key < T->lchild->data.key)\n return FALSE;\n r1 = IsBSTree(T->lchild);\n }\n \n if(T->rchild!=NULL)\n {\n if(T->data.key > T->rchild->data.key)\n return FALSE;\n r2 = IsBSTree(T->rchild);\n }\n return r1&&r2;\n}"
},
{
"id": "DC06PE66",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid OrderOut(BSTree T, KeyType k, void(*visit)(TElemType))\n{ \n if(T==NULL)\n return;\n //先访问右结点,然后访问根结点,然后访问左结点。\n OrderOut(T->rchild,k,visit);\n if(T->data.key>=k)\n visit(T->data);\n OrderOut(T->lchild,k,visit);\n}"
},
{
"id": "DC06PE67",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus InsertBST_I(BSTree &T, TElemType k) \n{ \n BSTree pNode = (BSTree)malloc(sizeof(BSTNode));\n memset(pNode,0,sizeof(BSTNode));\n pNode->data = k;\n if(T==NULL)\n {\n T=pNode;\n return OK;\n }\n BSTree p = T;\n\n while(1)\n {\n if(p->data.key == k.key)\n {\n return ERROR; \n }\n if(p->data.key > k.key)\n {\n if(p->lchild!=NULL&&p->lchild->data.key != NULL)\n p = p->lchild;\n else\n {\n p->lchild=pNode;\n return OK;\n }\n }\n else if(p->data.key < k.key)\n {\n if(p->rchild!=NULL&&p->rchild->data.key != NULL)\n p = p->rchild;\n else\n {\n p->rchild=pNode;\n return OK;\n }\n }\n }\n}"
},
{
"id": "DC06PE68",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nbool FindPath(BiTree T, TElemType c, Stack& S)\n{\n if(T==NULL)\n return FALSE;\n if(T->data == c)\n return TRUE;\n SElemType tmp;\n tmp.tag = 0;\n if(FindPath(T->lchild, c, S)|| FindPath(T->rchild, c, S))\n {\n tmp.ptr = T;\n Push(S, tmp);\n }\n else return FALSE;\n return TRUE;\n}\n\nBiTree CommAncestor(BiTree root, TElemType a, TElemType b)\n{\n if(root == NULL || a==root->data || b==root->data) \n return NULL; \n \n Stack S1, S2; \n InitStack(S1); \n InitStack(S2); \n \n if(FindPath(root, a, S1)==FALSE)\n return NULL;\n if(FindPath(root, b, S2)==FALSE)\n return NULL; \n \n SElemType par1, par2, par;\n do{\n par = par1;\n Pop(S1, par1);\n Pop(S2, par2);\n }while(StackEmpty(S1)!=TRUE && StackEmpty(S2)!=TRUE && par1.ptr==par2.ptr);\n if(par1.ptr==par2.ptr)\n return par1.ptr;\n else return par.ptr;\n}"
},
{
"id": "DC06PE75",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nBSTNode *Ranking(BSTree T, int k) \n{ \n //第k小的结点左子树有k-1个结点\n //那么lsize==k的话,说明这个结点是第k小结点\n if(T==NULL)\n return ERROR;\n if(T->lsize == k)\n return T;\n if(T->lsize > k)\n return Ranking(T->lchild,k);\n if(T->lsize < k)\n return Ranking(T->rchild,k - T->lsize);//减去左子树T->lsize-1包括结点T一共T->lsize个结点 \n}"
},
{
"id": "DC06PE77",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint Depth_BF(BBSTree T) \n{ \n if(T==NULL)\n return 0;\n int r1 = Depth_BF(T->lchild);\n int r2 = Depth_BF(T->rchild);\n T->bf = r1-r2;\n return 1 + (r1 > r2 ? r1 : r2);\n}"
},
{
"id": "DC06PE82",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nvoid RightBalance(BBSTree &T) \n{ \n BBSTree rc,ld;\n rc = T->rchild;\n switch(rc->bf)\n {\n case RH:\n T->bf = rc->bf = EH; \n L_Rotate(T);\n break;\n case LH:\n ld = rc->lchild;\n switch(ld->bf)\n {\n case LH: T->bf = EH; rc->bf = LH; break;\n case EH: T->bf = rc->bf = EH; break;\n case RH: T->bf = RH; rc->bf = EH; break;\n }\n ld->bf = EH;\n R_Rotate(T->rchild);\n L_Rotate(T);\n break;\n }\n}"
},
{
"id": "DC08PE12",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus CreateDG(MGraph &G, VexType *vexs, int n,\n ArcInfo *arcs, int e) \n{ \n InitGraph(G, DG, n);//空图\n G.n = n;\n G.e = e;\n G.kind = DG;\n for(int i=0;i<n;i++)\n {\n G.vexs[i]=vexs[i];\n }\n \n int i,j;\n for(int k=0;k<G.e;k++)\n {\n i=LocateVex(G, arcs[k].v);\n j=LocateVex(G, arcs[k].w);\n G.arcs[i][j].adj=1;\n }\n return OK;\n}"
},
{
"id": "DC08PE15",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint NextAdjVex(MGraph G, int k, int m) \n{ \n //邻接数组 下一个邻接结点\n int info;\n if(G.n==0&&k==0&&m==0) \n return 0;\n if(k<0||k>=G.n)\n return -1;\n if(G.kind==UDG||G.kind==DG)\n info = 0;\n if(G.kind==UDN||G.kind==DN)\n info = INFINITY;\n \n for(int i=m+1;i<G.n;i++)\n {\n if(G.arcs[k][i].adj!=info)\n {\n return i;\n }\n }\n return -1;\n}"
},
{
"id": "DC08PE17",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus SetArc(MGraph &G, VexType v, VexType w, ArcCell info) \n{ \n int i,j;\n i = LocateVex(G, v);\n j = LocateVex(G, w);\n if(i<0||j<0)\n return ERROR;\n G.arcs[i][j] = info;\n G.e++;\n}"
},
{
"id": "DC08PE21",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint outDegree(ALGraph G, int k) \n{ \n //邻接表,有向图,k顶点的出度\n if(k>=G.n||k<0)\n return -1;\n AdjVexNode* p = G.vexs[k].firstArc;\n int od = 0;\n while(p)\n {\n p = p->next;\n od++;\n }\n return od;\n}"
},
{
"id": "DC08PE22",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nint inDegree(ALGraph G, int k) \n{ \n //邻接表,有向图,k顶点的入度\n if(k>=G.n||k<0)\n return -1;\n AdjVexNode* p;\n int id = 0;\n for(int i=0;i<G.n;i++)\n {\n //G.vexs[i]\n p = G.vexs[i].firstArc;\n while(p)\n {\n if(p->adjvex == k)\n {\n id++;\n break;\n }\n p = p->next;\n }\n }\n return id;\n}"
},
{
"id": "DC08PE32",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus CreateDG(ALGraph &G, VexType *vexs, int n,\n ArcInfo *arcs, int e) \n{\n int i,j,k;\n AdjVexNodeP p;\n G.n = n;\n G.e = e;\n G.kind = DG;\n //G.vexs = (VexNode*)malloc(n*sizeof(VexNode));\n G.tags = (int*)malloc(sizeof(int) * n);\n for(int i=0;i<n;i++)\n {\n G.tags[i] = UNVISITED;\n G.vexs[i].data = vexs[i];\n G.vexs[i].firstArc = NULL;\n }\n for(int k=0;k<e;k++)\n {\n i=LocateVex(G, arcs[k].v);\n j=LocateVex(G, arcs[k].w);\n if(i<0||j<0) return ERROR;\n p = (AdjVexNode*)malloc(sizeof(AdjVexNode));\n p->adjvex = j;\n p->next = G.vexs[i].firstArc;\n G.vexs[i].firstArc = p;\n }\n return OK;\n}"
},
{
"id": "DC08PE34",
"code": "#include \"allinclude.h\" //DO NOT edit this line\nStatus CreateUDG(ALGraph &G, VexType *vexs, int n,\n ArcInfo *arcs, int e) \n{ \n int i,j,k;\n AdjVexNodeP p;\n G.n = n;\n G.e = e;\n G.kind = DG;\n //G.vexs = (VexNode*)malloc(n*sizeof(VexNode));\n G.tags = (int*)malloc(sizeof(int) * n);\n for(int i=0;i<n;i++)\n {\n G.tags[i] = UNVISITED;\n G.vexs[i].data = vexs[i];\n G.vexs[i].firstArc = NULL;\n }\n for(int k=0;k<e;k++)\n {\n i=LocateVex(G, arcs[k].v);\n j=LocateVex(G, arcs[k].w);\n if(i<0||j<0) return ERROR;\n p = (AdjVexNode*)malloc(sizeof(AdjVexNode));\n p->adjvex = j;\n p->next = G.vexs[i].firstArc;\n G.vexs[i].firstArc = p;\n \n p = (AdjVexNode*)malloc(sizeof(AdjVexNode));\n p->adjvex = i;\n p->next = G.vexs[j].firstArc;\n G.vexs[j].firstArc = p;\n }\n return OK;\n}"
}
]