// 逆置/排序(冒泡)/合并void Reverse(PLinkList* ppListvoid DelNonTailNode(Node* n);void InsertFrontNode(Node* n, DataType x);void Sort(PLinkList pList);PLinkList Merge(PLinkList l1, PLinkList l2);PLinkList MergeRecursive(PLinkList l1, PLinkList l2);// 刪除單鏈表的一個(gè)非尾節(jié)點(diǎn)void DelNonTailNode(Node* n){ Node* del = 0; // 斷言是否是尾節(jié)點(diǎn) assert(n->_next); // 將n的下一個(gè)next節(jié)點(diǎn)的值賦值給n, 刪除n的next節(jié)點(diǎn),單鏈表和面試題
。 n->_data = n->_next->_data; del = n->_next; n->_next = n->_next->_next; free(del);}// 在當(dāng)前節(jié)點(diǎn)前插入一個(gè)數(shù)據(jù)xvoid InsertFrontNode(Node* n, DataType x){ DataType tmpData; Node* tmpNode = CreateNode(x); assert(n); // 數(shù)據(jù)插到當(dāng)前節(jié)點(diǎn)后 tmpNode->_next = n->_next; n->_next = tmpNode; // 交換數(shù)據(jù) tmpData = n->_data; n->_data = tmpNode->_data; tmpNode->_data = tmpData;}////約瑟夫環(huán)(約瑟夫問(wèn)題)是一個(gè)數(shù)學(xué)的應(yīng)用問(wèn)題:已知n個(gè)人(以編號(hào)1,2,3...n分別表示)圍坐在一張//圓桌周?chē)木幪?hào)為k的人開(kāi)始報(bào)數(shù),數(shù)到m的那個(gè)人出列;他的下一個(gè)人又從1開(kāi)始報(bào)數(shù),數(shù)到m的那個(gè)人//又出列;依此規(guī)律重復(fù)下去,直到圓桌周?chē)娜巳砍隽小?/Node* JosephCycle(PLinkList pList, int m){ Node* begin = pList; assert(pList); while (1) { Node* del = 0; int i = 0; // 判斷只有一個(gè)節(jié)點(diǎn)時(shí)退出 if (begin->_next == begin) { break; } // 跳m-1步 for (; i < m - 1; ++i) { begin = begin->_next; } printf("%d", begin->_data); // 替換刪除法進(jìn)行刪除 del = begin->_next; begin->_data = begin->_next->_data; begin->_next = begin->_next->_next; free(del); } return begin;}// 逆置void Reverse(PLinkList* ppList){ Node* head = 0; Node* next = 0; assert(ppList); // 無(wú)節(jié)點(diǎn)或只有一個(gè)節(jié)點(diǎn)則直接返回 if (*ppList == NULL || (*ppList)->_next == NULL) { return; } // 取出next節(jié)點(diǎn) next = (*ppList)->_next; // 取出頭結(jié)點(diǎn)并置空尾指針 head = *ppList; head->_next = 0; // 從第二個(gè)節(jié)點(diǎn)開(kāi)始進(jìn)行頭插。 while (next) { Node* tmp = next; next = next->_next; tmp->_next = head; head = tmp; } // 更新頭結(jié)點(diǎn)指針 *ppList = head;}// 排序-(冒泡升序排序)void BubbleSort(PLinkList pList, Node* end){ // 優(yōu)化標(biāo)記 int exchange = 0; Node* prev = 0; Node* next = 0; Node* tail = 0; // 沒(méi)有節(jié)點(diǎn) or 一個(gè)節(jié)點(diǎn)則直接返回 if (pList == end || pList->_next == end) { return; } // tail做尾標(biāo)記 tail = end; while (tail != pList) { // 將數(shù)據(jù)向后冒 prev = pList; next = pList->_next; while (next != tail) { if (prev->_data > next->_data) { DataType tmp = prev->_data; prev->_data = next->_data; next->_data = tmp; exchange = 1; } prev = next; next = next->_next; } if (exchange == 0) { return; } // 更新尾標(biāo)記 tail = prev; }}//// 使用前后指針版的快速排序//Node* Partion(Node* left, Node* right, int& leftCnt, int& rightCnt){ Node* key = left; Node* prev = left, *next = left->_next; leftCnt = 0, rightCnt = 0; int totalCnt = 0; while (next != right) { if (next->_data <= key->_data) { prev = prev->_next; if (prev != next) { swap(prev->_data, next->_data); } leftCnt++; } next = next->_next; totalCnt++; } rightCnt = totalCnt - leftCnt; if (prev != key) { swap(prev->_data, key->_data); } return prev;}// 排序優(yōu)化->快速排序void QucikSort_OP(PLinkList left, PLinkList right){ int leftCnt, rightCnt; // 一個(gè)節(jié)點(diǎn)或者一個(gè) if ((left != right) && (left && left->_next != right)) { Node* key = Partion(left, right, leftCnt, rightCnt); if (leftCnt < 13) { BubbleSort(left, key); } else { QucikSort_OP(left, key); } if (rightCnt < 13) { BubbleSort(key->_next, right); } else { QucikSort_OP(key->_next, right); } }}// 合并兩個(gè)有序鏈表,合并后的鏈表依然有序PLinkList Merge(PLinkList pList1, PLinkList pList2){ PLinkList mergePList; Node* tail = 0; Node* begin1 = 0; Node* begin2 = 0; // 若兩個(gè)鏈表相同,則直接返回 if (pList1 == pList2) { return pList1; } // 若其中一個(gè)鏈表為空,則返回另一個(gè)鏈表 if (pList1 == NULL) { return pList2; } if (pList2 == NULL) { return pList2; } // 取出數(shù)據(jù)小的節(jié)點(diǎn)為新鏈表的頭結(jié)點(diǎn)。 begin1 = pList1; begin2 = pList2; if (begin1->_data < begin2->_data) { mergePList = begin1; begin1 = begin1->_next; } else { mergePList = begin2; begin2 = begin2->_next; } // 標(biāo)記尾節(jié)點(diǎn),方便歸并的數(shù)據(jù)尾插。 tail = mergePList; while (begin1 && begin2) { if (begin1->_data < begin2->_data) { tail->_next = begin1; begin1 = begin1->_next; tail = tail->_next; } else { tail->_next = begin2; begin2 = begin2->_next; tail = tail->_next; } } // 鏈接剩余尾鏈表 if (begin1) { tail->_next = begin1; } else if (begin2) { tail->_next = begin2; } return mergePList;}// 遞歸實(shí)現(xiàn)鏈表合并PLinkList MergeRecursive(PLinkList pList1, PLinkList pList2){ PLinkList mergePList; // 若兩個(gè)鏈表相同,則直接返回 if (pList1 == pList2) { return pList1; } // 若其中一個(gè)鏈表為空,則返回另一個(gè)鏈表 if (pList1 == NULL) { return pList2; } if (pList2 == NULL) { return pList2; } if (pList1->_data < pList2->_data) { mergePList = pList1; mergePList->_next = MergeRecursive(pList1->_next, pList2); } else { mergePList = pList2; mergePList->_next = MergeRecursive(pList1, pList2->_next); } return mergePList;}// 【快慢指針問(wèn)題】// 查找單鏈表的中間節(jié)點(diǎn)PLinkList FindMidNode(PLinkList pList){ // 快慢指針,快指針一次走兩步,慢指針一次走一步。 PLinkList slow, fast; if (pList == NULL) { return pList; } slow = pList; fast = pList; while (fast && fast->_next) { slow = slow->_next; fast = fast->_next->_next; } // // fast 為空則鏈表長(zhǎng)度為偶數(shù),slow為中間節(jié)點(diǎn)。 // fast->next為空則鏈表長(zhǎng)度為奇數(shù),slow為中間節(jié)點(diǎn)。 // return slow;}// 刪除單鏈表的倒數(shù)第k個(gè)節(jié)點(diǎn)(k > 1 && k < 鏈表的總長(zhǎng)度);// 時(shí)間復(fù)雜度O(N)void DelKNode(PLinkList pList,int k){ PLinkList slow, fast; if (pList == NULL) { return; } slow = pList; fast = pList; assert(k > 1); // 快指針走k步以后,慢指針才開(kāi)始移動(dòng) while (fast) { if (--k < 0) { slow = slow->_next; } fast = fast->_next; } if (k < 0) { Node* del = slow->_next; slow->_data = slow->_next->_data; slow->_next = slow->_next->_next; free(del); }}// 【鏈表帶環(huán)問(wèn)題】// 判斷鏈表是否帶環(huán), 若鏈表帶環(huán)則求環(huán)的長(zhǎng)度和相遇節(jié)點(diǎn),不帶環(huán)返回-1int CheckCycle(PLinkList pList, PLinkList* meetNode){ PLinkList slow, fast; if (pList == NULL) { return -1; } slow = pList; fast = pList; // // 使用快慢指針,當(dāng)快指針追上慢指針,則表示有環(huán),否則表示無(wú)環(huán)。 // while (fast && fast->_next) { slow = slow->_next; fast = fast->_next->_next; if (slow == fast) { // 慢指針再跑一圈,計(jì)算環(huán)的長(zhǎng)度。 int cycleLength = 0; *meetNode = fast; do{ slow = slow->_next; ++cycleLength; } while (slow != fast); return cycleLength; } } // 鏈表不帶環(huán)則返回-1 return -1;}// 獲取環(huán)入口點(diǎn)Node* GetCycleEntryNode(PLinkList pList, PLinkList meetNode){ int length1 = 0, length2 = 0, interval = 0; Node* begin1 = pList, *begin2 = meetNode->_next; assert(pList); assert(meetNode); // // 1:模擬從相遇節(jié)點(diǎn)斷開(kāi)環(huán),則轉(zhuǎn)換為兩單鏈表相交,求交點(diǎn)的問(wèn)題。 // while (begin1 != meetNode) { begin1 = begin1->_next; ++length1; } while (begin2 != meetNode) { begin2 = begin2->_next; ++length2; } // 2:先計(jì)算兩個(gè)鏈表的長(zhǎng)度,長(zhǎng)的鏈表先走interval(兩鏈表長(zhǎng)度的差值)步。 begin1 = pList, begin2 = meetNode->_next; // 重置鏈表起點(diǎn) if (length1 > length2) { interval = length1 - length2; while (interval--) { begin1 = begin1->_next; } } else if (length1 < length2) { interval = length2 - length1; while (interval--) { begin2 = begin2->_next; } } // 3:則第一次相遇的節(jié)點(diǎn)為環(huán)的入口點(diǎn)。 while (begin1 != begin2) { begin1 = begin1->_next; begin2 = begin2->_next; } return begin1;}// 【鏈表相交問(wèn)題】//// 判斷兩個(gè)鏈表是否相交,假設(shè)兩個(gè)鏈表都不帶環(huán)。// 求環(huán)的交點(diǎn),長(zhǎng)鏈表先走n步(n為兩鏈表的長(zhǎng)度差),然后再一起走,第一個(gè)相遇點(diǎn)則為交點(diǎn)。//int CheckCross(PLinkList pList1, PLinkList pList2){ Node* end1 = 0, *end2 = 0; assert(pList1 && pList2); while (pList1) { end1 = pList1; pList1 = pList1->_next; } while (pList2) { end2 = pList2; pList2 = pList2->_next; } if (end1 == end2) { return 1; } return 0;}//// 復(fù)雜鏈表的復(fù)制。// 一個(gè)鏈表的每個(gè)節(jié)點(diǎn),有一個(gè)指向next指針指向下一個(gè)節(jié)點(diǎn),還有一個(gè)random指針指向這// 個(gè)鏈表中的一個(gè)隨機(jī)節(jié)點(diǎn)或者NULL,現(xiàn)在要求實(shí)現(xiàn)復(fù)制這個(gè)鏈表,返回復(fù)制后的新鏈表。//typedef struct ComplexNode{ DataType _data; // 數(shù)據(jù) struct ComplexNode* _next;// 指向下一個(gè)節(jié)點(diǎn)的指針 struct ComplexNode* _random;// 指向隨機(jī)節(jié)點(diǎn)}ComplexNode;ComplexNode* CreateComplexNode(DataType x){ ComplexNode* tmp = new ComplexNode; tmp->_data = x; tmp->_next = NULL; tmp->_random = NULL; return tmp;}void CreateComplexNode(ComplexNode*& head){ ComplexNode* n1 = CreateComplexNode(1); ComplexNode* n2 = CreateComplexNode(2); ComplexNode* n3 = CreateComplexNode(3); ComplexNode* n4 = CreateComplexNode(4); n1->_next = n2; n2->_next = n3; n3->_next = n4; n4->_next = NULL; n1->_random = n4; n2->_random = n3; n3->_random = n2; n4->_random = n1; head = n1;}void PrintComplexList(ComplexNode* head){ while (head) { printf("【%d】", head->_data); printf(":random->%d", head->_random->_data); printf(":next->"); head = head->_next; } printf("NULL\n");}ComplexNode* CopyComplexList(ComplexNode* cpList){ ComplexNode* head = cpList; // 1.將copy出新鏈表的節(jié)點(diǎn)插在原鏈表每個(gè)節(jié)點(diǎn)的后面 head = cpList; while (head) { ComplexNode* tmp = CreateComplexNode(head->_data); ComplexNode* prev = head; head = head->_next; prev->_next = tmp; tmp->_next = head; } // 2.處理copy鏈表節(jié)點(diǎn)的random指向 head = cpList; while (head) { ComplexNode* random = head->_random; ComplexNode* next = head->_next; if (random) { next->_random = random->_next; } head = head->_next->_next; } // 3.摘下copy鏈表節(jié)點(diǎn),構(gòu)建出copy鏈表 head = cpList; ComplexNode* newHead, *newTail; if (head) { newHead = head->_next; newTail = head->_next; // 摘下copy節(jié)點(diǎn) head->_next = head->_next->_next; head = head->_next; } while (head) { newTail->_next = head->_next; newTail = newTail->_next; // 摘下copy節(jié)點(diǎn) head->_next = head->_next->_next; head = head->_next; } return newHead;}#include<stdio.h>#include <iostream>usingnamespace std;#include "Slist.h"http:// 測(cè)試PushBackvoidTest1(){ PLinkList pList; printf("Test PushBack begin\n"); InitSList(&pList); PushBack(&pList,1); PushBack(&pList,2); PushBack(&pList,3); PushBack(&pList,4); PrintSList(pList); DestorySList(&pList); printf("Test PushBack end\n\n");}// 測(cè)試PopBackvoidTest2(){ PLinkList pList; printf("Test PopBack begin\n"); InitSList(&pList); PushBack(&pList,1); PushBack(&pList,2); PushBack(&pList,3); PushBack(&pList,4); PrintSList(pList); PopBack(&pList); PopBack(&pList); PopBack(&pList); PopBack(&pList); PrintSList(pList); DestorySList(&pList); printf("Test PopBack end\n\n");}// PushFrontvoidTest3(){ PLinkList pList; printf("Test PushFront begin\n"); InitSList(&pList); PushFront(&pList,1); PushFront(&pList,2); PushFront(&pList,3); PushFront(&pList,4); PrintSList(pList); DestorySList(&pList); printf("Test PushFront end\n\n");}// PopFrontvoidTest4(){ PLinkList pList; printf("Test PopFront begin\n"); InitSList(&pList); PushFront(&pList,1); PushFront(&pList,2); PushFront(&pList,3); PushFront(&pList,4); PrintSList(pList); PopFront(&pList); PopFront(&pList); PopFront(&pList); PopFront(&pList); PrintSList(pList); DestorySList(&pList); printf("Test PopFront end\n\n");}// FindvoidTest5(){ PLinkList pList; printf("Test Find begin\n"); InitSList(&pList); PushFront(&pList,1); PushFront(&pList,2); PushFront(&pList,3); PushFront(&pList,4); PrintSList(pList); if (Find(pList,4)) { printf("Find 4 Success\n"); } if (Find(pList,5) ==0) { printf("Not Find 5\n"); } DestorySList(&pList); printf("Test Find end\n\n");}// RemovevoidTest6(){ PLinkList pList; printf("Test Remove begin\n"); InitSList(&pList); PushFront(&pList,1); PushFront(&pList,2); PushFront(&pList,3); PushFront(&pList,4); PrintSList(pList); Remove(&pList,1); Remove(&pList,2); Remove(&pList,3); Remove(&pList,4); PrintSList(pList); DestorySList(&pList); printf("Test Remove end\n\n");}// InsertvoidTest7(){ PLinkList pList; printf("Test Insert begin\n"); InitSList(&pList); Insert(&pList, pList,1); Insert(&pList, pList,2); Insert(&pList, pList,3); PrintSList(pList); DestorySList(&pList); printf("Test Insert end\n\n");}// ErasevoidTest8(){ Node* del = 0; PLinkList pList; printf("Test Erase begin\n"); InitSList(&pList); PushFront(&pList,1); PushFront(&pList,2); PrintSList(pList); del = Find(pList,1); Erase(&pList, del); del = Find(pList,2); Erase(&pList, del); PrintSList(pList); DestorySList(&pList); printf("Test Erase end\n\n");}/////////////////////////////////////////////////////////////////////////////////// 面試題測(cè)試// ReversevoidTest9(){ Node* del = 0; PLinkList pList; printf("Test Reverse begin\n"); InitSList(&pList); PushFront(&pList,1); PushFront(&pList,2); PushFront(&pList,3); PushFront(&pList,4); PrintSList(pList); Reverse(&pList); PrintSList(pList); DestorySList(&pList); printf("Test Reverse end\n\n");}// Sort & SortOPvoidTest10(){ Node* del = 0; PLinkList pList; printf("Test Sort begin\n"); InitSList(&pList); //PushFront(&pList, 6); //PushFront(&pList, 4); //PushFront(&pList, 1); //PushFront(&pList, 5); //PushFront(&pList, 3); //PushFront(&pList, 2); //PushFront(&pList, 7); //PushFront(&pList, 8); //PushFront(&pList, 8); //PushFront(&pList, 9); //PushFront(&pList, 0); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,4); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,4); PushBack(&pList,4); PushBack(&pList,4); PushBack(&pList,4); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,2); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,3); PushBack(&pList,4); PushBack(&pList,4); PushBack(&pList,4); PushBack(&pList,3); PushBack(&pList, 3); PushBack(&pList,3); PushBack(&pList,4); PrintSList(pList); //BubbleSort(pList); QucikSort_OP(pList,NULL); PrintSList(pList); DestorySList(&pList); printf("Test Sort end\n\n");}// MergevoidTest11(){ Node* del = 0; PLinkList pList1; PLinkList pList2; PLinkList mergePList; printf("Test Merge begin\n"); InitSList(&pList1); InitSList(&pList2); InitSList(&mergePList); PushFront(&pList1, 1); PushFront(&pList1,2); PushFront(&pList1,3); PushFront(&pList1,4); PushFront(&pList2,10); PrintSList(pList1); PushFront(&pList2,0); PushFront(&pList2,1); PushFront(&pList2,5); PushFront(&pList2,8); PushFront(&pList2,9); PrintSList(pList2); BubbleSort(pList1,NULL); BubbleSort(pList2,NULL); mergePList = Merge(pList1, pList2); PrintSList(mergePList); DestorySList(&mergePList); printf("Test Merge end\n\n");}// MergeRecursivevoidTest12(){ Node* del = 0; PLinkList pList1; PLinkList pList2; PLinkList mergePList; printf("Test MergeRecursive begin\n"); InitSList(&pList1); InitSList(&pList2); InitSList(&mergePList); PushFront(&pList1,1); PushFront(&pList1,2); PushFront(&pList1,3); PushFront(&pList1,4); PushFront(&pList2,10); PrintSList(pList1); PushFront(&pList2,0); PushFront(&pList2,1); PushFront(&pList2,5); PushFront(&pList2,8); PushFront(&pList2,9); PrintSList(pList2); BubbleSort(pList1,NULL); BubbleSort(pList2,NULL); mergePList = MergeRecursive(pList1, pList2); PrintSList(mergePList); DestorySList(&mergePList); printf("Test MergeRecursive end\n\n");}// DelNonTailNodevoidTest13(){ Node* del = 0; PLinkList pList; printf("Test DelMidNode begin\n"); InitSList(&pList); PushFront(&pList, 1); PushFront(&pList, 2); PushFront(&pList, 3); PushFront(&pList, 4); PrintSList(pList); del = Find(pList,3); DelNonTailNode(del); PrintSList(pList); DestorySList(&pList); printf("Test DelMidNode end\n\n");}// InsertFrontNodevoidTest14(){ Node* n = 0; PLinkList pList; printf("Test InsertFrontNode begin\n"); InitSList(&pList); PushFront(&pList,1); PushFront(&pList,2); PushFront(&pList,3); PushFront(&pList,4); PrintSList(pList); n = Find(pList,3); InsertFrontNode(n,0); PrintSList(pList); DestorySList(&pList); printf("Test InsertFrontNode end\n\n");}// FindMidNodevoidTest15(){ Node* n = 0; PLinkList pList; printf("Test FindMidNode begin\n"); InitSList(&pList); PushBack(&pList,1); PushBack(&pList,2); PushBack(&pList,3); PushBack(&pList,4); PrintSList(pList); n = FindMidNode(pList); printf("Mid:%d\n", n->_data); PushBack(&pList,5); PrintSList(pList); n = FindMidNode(pList); printf("Mid:%d\n", n->_data); DestorySList(&pList); printf("Test FindMidNode end\n\n");}// DelKNodevoidTest16(){ Node* n = 0; PLinkList pList; printf("Test DelKNode begin\n"); InitSList(&pList); PushBack(&pList,1); PushBack(&pList,2); PushBack(&pList,3); PushBack(&pList,4); PrintSList(pList); DelKNode(pList,3); PrintSList(pList); DestorySList(&pList); printf("Test DelKNode end\n\n");}// CheckCyclevoidTest17(){ int length = 0; Node* realEntry = 0, *getEntry = 0; Node* end = 0; PLinkList pList; PLinkList meetNode = 0; printf("Test CheckCycle begin\n"); InitSList(&pList); PushBack(&pList,1); PushBack(&pList,2); PushBack(&pList,3); PushBack(&pList,4); PushBack(&pList,5); PushBack(&pList,6); PushBack(&pList,7); PrintSList(pList); length = CheckCycle(pList, &meetNode); printf("Plist Length:%d\n",length); // 創(chuàng)建帶環(huán)鏈表 end = Find(pList,7); realEntry = Find(pList,4); end->_next = realEntry; printf("realEntry:%d\n",realEntry->_data); length = CheckCycle(pList, &meetNode); printf("Plist Length:%d, meetNode:%d\n", length, meetNode->_data); getEntry = GetCycleEntryNode(pList, meetNode); printf("realEntry:%d, getEntry:%d\n", realEntry->_data, getEntry->_data); // 解環(huán) end->_next = 0; DestorySList(&pList); printf("Test CheckCycLeLength end\n\n");}// CheckCrossvoidTest18(){ PLinkList pList1, pList2; Node* realCrossNode, *end; printf("Test CheckCross begin\n"); InitSList(&pList1); InitSList(&pList2); PushBack(&pList1,1); PushBack(&pList1,2); PushBack(&pList1,3); PushBack(&pList1,4); PushBack(&pList1,5); PushBack(&pList1,6); PushBack(&pList1,7); PrintSList(pList1); PushBack(&pList2,10); PushBack(&pList2,11); PushBack(&pList2,12); PrintSList(pList2); printf("Cross:%d\n",CheckCross(pList1, pList2)); // 創(chuàng)建相交鏈表 realCrossNode = Find(pList1, 4); end = Find(pList2,12); end->_next = realCrossNode; printf("Cross:%d\n",CheckCross(pList1, pList2)); // 解開(kāi) end->_next = NULL; DestorySList(&pList1); DestorySList(&pList2); printf("Test CheckCycLeLength end\n\n");}// JosephCyclevoidTest19(){ Node* end; PLinkList pList; printf("Test JosephCycle begin\n"); InitSList(&pList); PushBack(&pList,1); PushBack(&pList,2); PushBack(&pList,3); PushBack(&pList,4); PushBack(&pList,5); PushBack(&pList,6); PushBack(&pList,7); PrintSList(pList); // 創(chuàng)建帶環(huán)鏈表 end = Find(pList, 7); end->_next = pList; printf("JosephCycle:%d\n",JosephCycle(pList,3)->_data); printf("Test JosephCycle end\n\n");}// 復(fù)雜鏈表的復(fù)制voidTest20(){ ComplexNode* cpList; CreateComplexNode(cpList); PrintComplexList(cpList); ComplexNode* copyList = CopyComplexList(cpList); PrintComplexList(copyList);}intmain(){ //Test1(); //Test2(); //Test3(); //Test4(); //Test5(); //Test6(); //Test7(); //Test8(); //Test9(); //Test10(); //Test11(); //Test12(); //Test13(); //Test14(); //Test15(); //Test16(); //Test17(); //Test18(); //Test19(); //Test20(); return 0;}