《数据结构》线性表的顺序表示和实现
发布时间:2020-12-15 06:01:36 所属栏目:安全 来源:网络整理
导读:顺序表的插入算法 statusListInsert(List*L,inti,ElemTypee){structSTU*p,*q;if(i1||iL-length+1)returnERROR;q=(L-elem[i-1]);for(p=L-elem[L-length-1];p=q;--p)*(p+1)=*p;*q=e;++L-length;returnOK;}/*ListInsertBeforei*/ 顺序表的合并算法 voidMergeLis
顺序表的插入算法 statusListInsert(List*L,inti,ElemTypee){ structSTU*p,*q; if(i<1||i>L->length+1)returnERROR; q=&(L->elem[i-1]); for(p=&L->elem[L->length-1];p>=q;--p) *(p+1)=*p; *q=e; ++L->length; returnOK; }/*ListInsertBeforei*/ 顺序表的合并算法 voidMergeList(List*La,List*Lb,List*Lc){ ElemType*pa,*pb,*pc,*pa_last,*pb_last; pa=La->elem;pb=Lb->elem; Lc->listsize=Lc->length=La->length+Lb->length; pc=Lc->elem= (ElemType*)malloc(Lc->listsize*sizeof(ElemType)); if(!Lc->elem)exit(OVERFLOW); pa_last=La->elem+La->length-1; pb_last=Lb->elem+Lb->length-1; while(pa<=pa_last&&pb<=pb_last){ if(Less_EqualList(pa,pb))*pc++=*pa++; else*pc++=*pb++; } while(pa<=pa_last)*pc++=*pa++; while(pb<=pb_last)*pc++=*pb++; } 顺序表的查找算法 intLocateElem(List*La,ElemTypee,inttype){ inti; switch(type){ caseEQUAL: for(i=0;i<length;i++) if(EqualList(&La->elem[i],&e)) return1; break; default: break; } return0; } 顺序表的联合算法 voidUnionList(List*La,List*Lb){ intLa_len,Lb_len;inti;ElemTypee; La_len=ListLength(La);Lb_len=ListLength(Lb); for(i=0;i<Lb_len;i++){ GetElem(*Lb,i,&e); if(!LocateElem(La,e,EQUAL)) ListInsert(La,++La_len,e); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |