天天看点

c语言线性表无序合并,数据结构(C语言)顺序表的合并

满意答案

c语言线性表无序合并,数据结构(C语言)顺序表的合并

aanhbjttj

2013.09.01

c语言线性表无序合并,数据结构(C语言)顺序表的合并

采纳率:41%    等级:12

已帮助:15210人

程序没什么大的毛病。。只是一些编写代码时的小疏忽 #include #include #define ok 1 #define error 0 #define LIST_INT_SIZE 10 #define elemtype int typedef struct{ elemtype *elem; int length; int listsize; }sqlist; int Init_sqlist(sqlist *la) { (*la).elem=(elemtype*)malloc(LIST_INT_SIZE*sizeof(elemtype)); if(!(*la).elem)return error; (*la).length=0; (*la).listsize=LIST_INT_SIZE; return ok; } void mergelist_sq(sqlist la,sqlist lb,sqlist &lc) // 忘了加; void main() { int i;sqlist la,lb,lc; Init_sqlist(&la); Init_sqlist(&lb); for(i=0;i<5;i++) scanf("%d",la.elem[i]); // 应该改为 scanf( "%d",&la.elem[i] ); la.length=5; for(i=0;i<5;i++) scanf("%d",lb.elem[i]); // 同上 lb.length=5; mergelist_sq(la,lb,lc); } void mergelist_sq(sqlist la,sqlist lb,sqlist &lc) { int *pa,*pb,*pc,*pa_last,*pb_last,i; pa=la.elem;pb=lb.elem; lc.listsize=la.length+lb.length; pc=lc.elem=(elemtype*)malloc(lc.listsize*sizeof(elemtype)); pa_last=la.elem+la.length-1; pb_last=lb.elem+lb.length-1; while(pa<=pa_last&&pb<=pb_last){ if(*pa<=*pb)*pc++=*pa++; else *pc++=*pb++;} while(pa<=pa_last) *pc++=*pa++; while(pb<=pb_last) *pc++=*pb++; for(i=0;i

20分享举报