Posted on 2006-06-19 21:03
Enjoy Life 阅读(2538)
评论(1) 编辑 收藏 引用 所属分类:
DS study
void MergList_Sq(SqList La, SqList Lb, SqList &Lc){
ElemType *pa,*pb,*pc;
int pa_length,pb_length,pc_length;
pa_length = La.length;
pb_length = Lb.length;
Lc.listsize = pa_length + pb_length;
pc = (ElemType *)malloc(listsize * sizeof(ElemType));
if(!pc){
printf("malloc was failed\n");
return;
}
Lc.elem = pc;
pa = La.elem;
pb = Lb.elem;
while(pa<=&La.elem[La.length-1]&&pb<=&Lb.elem[Lb.length-1]){
if(*pa<=*pb)
*pc++=*pa++;
else
*pc++=*pb++;
}
while(pa<=&La.elem[La.length-1])
*pc++=*pa++;
while(pb<=&Lb.elem[Lb.length-1])
*pc++=*pb++
}//MergList_Sq