顺序表的插入算法
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); } }