int main() { ListNode* L1 = CreateListTail(5); L1 = SortList(L1); PrintList(L1); Sleep(1000); ListNode* L2 = CreateListTail(6); L2 = SortList(L2); PrintList(L2); ListNode* L = MergeSortedList(L1,L2); PrintList(L); /* FILETIME beg,end; GetSystemTimeAsFileTime(&beg); ListNode* L = CreateListTail(2000); GetSystemTimeAsFileTime(&end); PrintList(L); L = ReverseList(L); PrintList(L); unsigned long t = (100*(end.dwLowDateTime-beg.dwLowDateTime)); cout<<double(t)/1000<<"us"<<endl;*/ /* ListNode* p = L; while (p->m_pNext!=NULL) { p = p->m_pNext; }*/ // p->m_pNext = L->m_pNext->m_pNext->m_pNext->m_pNext->m_pNext->m_pNext; // cout<<FindLoopPort(L)->m_nValue<<endl; // ListNode* KthToTail = GetKthToTail(L,10); // cout<<KthToTail->m_nValue<<endl; system("pause"); return 0; }
int main() { LinkList L; ElemType e; Status i; int j,k; i=InitList(&L); printf("初始化L后:ListLength(L)=%d\n",ListLength(L)); for(j=1;j<=5;j++) i=ListInsert(&L,1,j); printf("在L的表头依次插入1~5后:L.data="); ListTraverse(L); printf("ListLength(L)=%d \n",ListLength(L)); i=ListEmpty(L); printf("L是否空:i=%d(1:是 0:否)\n",i); i=ClearList(&L); printf("清空L后:ListLength(L)=%d\n",ListLength(L)); i=ListEmpty(L); printf("L是否空:i=%d(1:是 0:否)\n",i); for(j=1;j<=10;j++) ListInsert(&L,j,j); printf("在L的表尾依次插入1~10后:L.data="); ListTraverse(L); printf("ListLength(L)=%d \n",ListLength(L)); ListInsert(&L,1,0); printf("在L的表头插入0后:L.data="); ListTraverse(L); printf("ListLength(L)=%d \n",ListLength(L)); GetElem(L,5,&e); printf("第5个元素的值为:%d\n",e); for(j=3;j<=4;j++) { k=LocateElem(L,j); if(k) printf("第%d个元素的值为%d\n",k,j); else printf("没有值为%d的元素\n",j); } k=ListLength(L); /* k为表长 */ for(j=k+1;j>=k;j--) { i=ListDelete(&L,j,&e); /* 删除第j个数据 */ if(i==ERROR) printf("删除第%d个数据失败\n",j); else printf("删除第%d个的元素值为:%d\n",j,e); } printf("依次输出L的元素:"); ListTraverse(L); j=5; ListDelete(&L,j,&e); /* 删除第5个数据 */ printf("删除第%d个的元素值为:%d\n",j,e); printf("依次输出L的元素:"); ListTraverse(L); i=ClearList(&L); printf("\n清空L后:ListLength(L)=%d\n",ListLength(L)); CreateListHead(&L,20); printf("整体创建L的元素(头插法):"); ListTraverse(L); i=ClearList(&L); printf("\n删除L后:ListLength(L)=%d\n",ListLength(L)); CreateListTail(&L,20); printf("整体创建L的元素(尾插法):"); ListTraverse(L); return 0; }