#include"list.c"voidPrintList(constListL)//打印鏈表{PositionP=Header(L);if(IsEmpty(L))printf("Emptylistn")">
線性表...............

線性表...............

ID:39623323

大?。?2.50 KB

頁(yè)數(shù):6頁(yè)

時(shí)間:2019-07-07

線性表..............._第1頁(yè)
線性表..............._第2頁(yè)
線性表..............._第3頁(yè)
線性表..............._第4頁(yè)
線性表..............._第5頁(yè)
資源描述:

《線性表...............》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)

1、#include#include"list.c"voidPrintList(constListL)//打印鏈表{PositionP=Header(L);if(IsEmpty(L))printf("Emptylist");else{do{P=Advance(P);printf("%d",Retrieve(P));}while(!IsLast(P,L));printf("");}}voidChange(ElementTypeX,ListL){PositionP,PPrev,PAfter

2、;P=Find(X,L);if(P->Next!=NULL){PPrev=FindPrevious(X,L);PAfter=P->Next;PPrev->Next=P->Next;P->Next=P->Next->Next;PAfter->Next=P;PrintList(L);}elseprintf("這是最后一個(gè)數(shù)字,不可交換。");}voidReverse(ListL)//創(chuàng)建一個(gè)新的鏈表將p1的元素插入到T鏈表中,實(shí)現(xiàn)倒置{ListT;PositionP1,P2;T=MakeEmpty(NULL

3、);P1=L->Next;P2=Header(T);while(P1)//P1不為零{Insert(P1->Element,T,P2);//在p2后面插入p1P1=P1->Next;//后動(dòng)}PrintList(T);}main(){ListL;PositionP;inti,X;inta[]={34,56,20,9,15,5};L=MakeEmpty(NULL);//清空鏈表P=Header(L);//取鏈表頭,list.c文件中的程序PrintList(L);for(i=0;i<6;i++){Insert

4、(a[i],L,P);//插入到鏈表中P=Advance(P);//p的下一個(gè)元素可改為p=p->next;}PrintList(L);printf("請(qǐng)輸入一個(gè)元素X:");scanf("%d",&X);Change(X,L);Reverse(L);return0;}#include#include"stackli.c"#defineN10voidConvert(intn,charstr[],unsignedp){inti,t;Stacks=CreateStack();while(n

5、!=0){Push(n%p,s);n=n/p;}for(i=0;!IsEmpty(s);i++){t=Top(s);if(t>=10)str[i]=t-10+'A';elsestr[i]=t+'0';Pop(s);}str[i]='