|
->24
1
2
3
4
5
6
7
8
9
12
13
21
28
30
42
77
插入前n=8;插入后n=9;
删除前n=8;删除后n=7; 逆风者
status ListInsert(List *L,int i,ElemType e) {
struct STU *p,*q;
if (i<1||i>L->length 1) return ERROR;
q=&(L->elem[i-1]);
for(p=&L->elem[L->length-1];p>=q;--p)
*(p 1)=*p;
*q=e;
L->length;
return OK;
}/*ListInsert Before i */
void MergeList(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 ;
}
顺序表的查找算法
int LocateElem(List *La,ElemType e,int type) {
int i;
switch (type) {
case EQUAL:
for(i=0;i<length;i )
if(EqualList(&La->elem[i],&e))
return 1;
break;
default:
break;
}
return 0;
}
顺序表的联合算法
void UnionList(List *La, List *Lb) {
int La_len,Lb_len; int i; ElemType e;
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);
}
}
三、C语言源程序范例
四、总结
线性表的顺序表示 顺序表的插入算法
顺序表的合并算法
本文章更多内容:<<上一页 - 1 - 2 |