freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

數(shù)據(jù)結(jié)構習題集答案(c版)(清華大學嚴蔚敏)(已修改)

2025-07-04 17:05 本頁面
 

【正文】 void print_descending(int x,int y,int z)//按從大到小順序輸出三個數(shù){scanf(%d,%d,%d,amp。x,amp。y,amp。z)。if(xy) xy。 //為表示交換的雙目運算符,以下同if(yz) yz。if(xy) xy。 //冒泡排序printf(%d %d %d,x,y,z)。}//print_descending Status fib(int k,int m,int amp。f)//求k階斐波那契序列的第m項的值f{int tempd。if(k2||m0) return ERROR。if(mk1) f=0。else if (m==k1) f=1。else{for(i=0。i=k2。i++) temp=0。temp[k1]=1。 //初始化for(i=k。i=m。i++) //求出序列第k至第m個元素的值{sum=0。for(j=ik。ji。j++) sum+=temp[j]。temp=sum。}f=temp[m]。}return OK。}//fib分析:通過保存已經(jīng)計算出來的結(jié)果,此方法的時間復雜度僅為O(m^2).如果采用遞歸編程(大多數(shù)人都會首先想到遞歸方法),則時間復雜度將高達O(k^m). typedef struct{char *sport。enum{male,female} gender。char schoolname。 //校名為39。A39。,39。B39。,39。C39。,39。D39?;?9。E39。char *result。int score。} resulttype。 typedef struct{int malescore。int femalescore。int totalscore。} scoretype。 void summary(resulttype result[ ])//求各校的男女總分和團體總分,假設結(jié)果已經(jīng)儲存在result[ ]數(shù)組中{scoretype score。i=0。while(!=NULL){switch(){case 39。A39。:score[ 0 ].totalscore+=。if(==0) score[ 0 ].malescore+=。else score[ 0 ].femalescore+=。break。case 39。B39。:+=。if(==0) +=。else +=。break?!?……?……}i++;}for(i=0。i5。i++){printf(School %d:\n,i)。printf(Total score of male:%d\n,)。printf(Total score of female:%d\n,)。printf(Total score of all:%d\n\n,)。}}//summary Status algo119(int a[ARRSIZE])//求i!*2^i序列的值且不超過maxint{last=1。for(i=1。i=ARRSIZE。i++){a[i1]=last*2*i。if((a[i1]/last)!=(2*i)) reurn OVERFLOW。last=a[i1]。return OK。}}//algo119分析:當某一項的結(jié)果超過了maxint時,它除以前面一項的商會發(fā)生異常. void polyvalue(){float ad。float *p=a。printf(Input number of terms:)。scanf(%d,amp。n)。printf(Input the %d coefficients from a0 to a%d:\n,n,n)。for(i=0。i=n。i++) scanf(%f,p++)。printf(Input value of x:)。scanf(%f,amp。x)。p=a。xp=1。sum=0。 //xp用于存放x的i次方for(i=0。i=n。i++){sum+=xp*(*p++)。xp*=x。}printf(Value is:%f,sum)。}//polyvalue Status DeleteK(SqList amp。a,int i,int k)//刪除線性表a中第i個元素起的k個元素{if(i1||k0||i+k1) return INFEASIBLE。for(count=1。i+count1=。count++) //注意循環(huán)結(jié)束的條件[i+count1]=[i+count+k1]。=k。return OK。}//DeleteK Status Insert_SqList(SqList amp。va,int x)//把x插入遞增有序表va中{if(+1) return ERROR。++。for(i=。xamp。amp。i=0。i)[i+1]=。[i+1]=x。return OK。}//Insert_SqList int ListComp(SqList A,SqList B)//比較字符表A和B,并用返回值表示結(jié)果,值為正,表示AB。值為負,表示AB。值為零,表示A=B{for(i=1。||。i++)if(!=) return 。return 0。}//ListComp LNode* Locate(LinkList L,int x)//鏈表上的元素查找,返回指針{for(p=lnext。pamp。amp。pdata!=x。p=pnext)。return p。}//Locate int Length(LinkList L)//求鏈表的長度{for(k=0,p=L。pnext。p=pnext,k++)。return k。}//Length void ListConcat(LinkList ha,LinkList hb,LinkList amp。hc)//把鏈表hb接在ha后面形成鏈表hc{hc=ha。p=ha。while(pnext) p=pnext。pnext=hb。}//ListConcat 見書后答案. Status Insert(LinkList amp。L,int i,int b)//在無頭結(jié)點鏈表L的第i個元素之前插入元素b{p=L。q=(LinkList*)malloc(sizeof(LNode))。=b。if(i==1){=p。L=q。 //插入在鏈表頭部}else{while(i1) p=pnext。qnext=pnext。pnext=q。 //插入在第i個元素的位置}}//Insert Status Delete(LinkList amp。L,int i)//在無頭結(jié)點鏈表L中刪除第i個元素{if(i==1) L=Lnext。 //刪除第一個元素else{p=L。while(i1) p=pnext。pnext=pnextnext。 //刪除第i個元素}}//Delete Status Delete_Between(Linklist amp。L,int mink,int maxk)//刪除元素遞增排列的鏈表L中值大于mink且小于maxk的所有元素{p=L。while(pnextdata=mink) p=pnext。 //p是最后一個不大于mink的元素if(pnext) //如果還有比mink更大的元素{q=pnext。while(qdatamaxk) q=qnext。 //q是第一個不小于maxk的元素pnext=q。}}//Delete_Between Status Delete_Equal(Linklist amp。L)//刪除元素遞增排列的鏈表L中所有值相同的元素{p=Lnext。q=pnext。 //p,q指向相鄰兩元素while(pnext){if(pdata!=qdata){p=pnext。q=pnext。 //當相鄰兩元素不相等時,p,q都向后推一步}else{while(qdata==pdata) {free(q)。q=qnext。 }pnext=q。p=q。q=pnext。 //當相鄰元素相等時刪除多余元素}//else}//while}//Delete_Equal void reverse(SqList amp。A)//順序表的就地逆置{for(i=1,j=。ij。i++,j)[j]。}//reverse void LinkList_reverse(Linklist amp。L)//鏈表的就地逆置。為簡化算法,假設表長大于2{p=Lnext。q=pnext。s=qnext。pnext=NULL。while(snext){qnext=p。p=q。q=s。s=snext。 //把L的元素逐個插入新表表頭}qnext=p。snext=q。Lnext=s。}//LinkList_reverse分析:本算法的思想是,逐個地把L的當前元素q插入新的鏈表頭部,p為新表表頭. void merge1(LinkList amp。A,LinkList amp。B,LinkList amp。C)//把鏈表A和B合并為C,A和B的元素間隔排列,且使用原存儲空間{p=Anext。q=Bnext。C=A。while(pamp。amp。q){s=pnext。pnext=q。 //將B的元素插入if(s){t=qnext。qnext=s。 //如A非空,將A的元素插入}p=s。q=t。}//while}//merge1 void reverse_merge(LinkList amp。A,LinkList amp。B,LinkList amp。C)//把元素遞增排列的鏈表A和B合并為C,且C中元素遞減排列,使用原空間{pa=Anext。pb=Bnext。pre=NULL。 //pa和pb分別指向A,B的當前元素while(pa||pb){if(padatapbdata||!pb){pc=pa。q=panext。panext=pre。pa=q。 //將A的元素插入新表}else{pc=pb。q=pbnext。pbnext=pre。pb=q。 //將B的元素插入新表}pre=pc。}C=A。Anext=pc。 //構造新表頭}//reverse_merge分析:本算法的思想是,按從小到大的順序依次把A和B的元素插入新表的頭部pc處,最后處理A或B的剩余元素. void SqList_Intersect(SqList A,SqList B,SqList amp。C)//求元素遞增排列的線性表A和B的元素的交集并存入C中{i=1。j=1。k=0。while(amp。amp。[j]){if([j]) i++。if([j]) j++。if(==[j]){[++k]=。 //當發(fā)現(xiàn)了一個在A,B中都存在的元素,i++。j++。 //就添加到C中}}//while}//SqList_Intersect void LinkList_Intersect(LinkList A,LinkList B,LinkList amp。C)//在鏈表結(jié)構上重做上題{p=Anext。q=Bnext。pc=(LNode*)malloc(sizeof(LNode))。while(pamp。amp。q){if(pdataqdata) p=pnext。else if(pdataqdata) q=qnext。else{s=(LNode*)malloc(sizeof(LNode))。sdata=pdata。pcnext=s。pc=s。p=pnext。q=qnext。}}//whileC=pc。}//LinkList_Intersect void SqList_Intersect_True(SqList amp。A,SqList B)//求元素遞增排列的線性表A和B的元素的交集并存回A中{i=1。j=1。k=0。while(amp。amp。[j]){if([j]) i++。else if([j]) j++。else if(!=[k]){[++k]=。 //當發(fā)現(xiàn)了一個在A,B中都存在的元素i++。j++。 //且C中沒有,就添加到C中}}//whilewhile([k]) [k++]=0。}//SqList_Intersect_True void LinkList_Intersect_True(LinkList amp。A,LinkList B)//在鏈表結(jié)構上重做上題{p=Anext。q=Bnext。pc=A。while(pamp。amp。q){if(pdataqdata) p=pnext。else if(pdataqdata) q=qnext。else if(pdata!=pcdata){pc=pcnext。pcdata=pdata。p=pnext。q=qnext。}}//while}//LinkList_Intersect_True void SqList_Intersect_Delete(SqList amp。A,SqList B,SqList C) {i=0。j=0。k=0。m=0。 //i指示A中元素原來的位置,m為移動后的位置while(iamp。amp。jamp。amp。 k) {if([j][k]) j++。else if([j][k]) k++。else{same=[j]。 //找到了相同元素samewhile([j]==same) j++。while([k]==same) k++。 //j,k后移到新的元素while(iamp。amp。same) [m++]=[i++]。 //需保留的元素移動到新位置while(iamp。amp。==same) i++。 //跳過相同的元素}}//whilewhil
點擊復制文檔內(nèi)容
范文總結(jié)相關推薦
文庫吧 www.dybbs8.com
公安備案圖鄂ICP備17016276號-1