/* 实验一(顺序表):设有非递减有序线性表 LA=(3,5,8,11)和LB=(2,6,8,9,11,15,20), 若LA 和LB 分别表示两个集合A 和B,求新集合A=AUB(‘并’操作,相同元素不保留); 预测输出:LA=(3, 5, 8, 11, 2, 6, 9, 15, 20) */ //以下是求集合A=AUB 的算法 /* status merge(sqlist &la,sqlist lb) {// 将 lb 中和la 中元素不同的数据元素归并至 la 中 len=la
length;//la 中元素的个数 q=la
elem+len;//q 为插入位置 pa=la
elem; pb_last=lb
elem+lb
length-1;//lb中表尾元素的地址 for(pb=lb
elem;pb=la
listsize)//若容量不够,增加分配 { newbase=(int *)realloc(la
elem,(la
listsize+LISTINCREMENT)*sizeof(int)); if(
newbase) exit(OVERFLOW); la
elem=newbase; la
listsize+=LISTINCREMENT; q=la
elem+la
length;//q 为插入位置 }// end if *q++=*pb; (la
length)++; }//end if }// end for return OK; }//merge */ //以下是程序 #include #include #include #define LISTINCREMENT 10 #define OK 1 #define ERROR 0 #define OVERFLOW -1 /* 类型定义 */ typedef struct{ int *elem; int lengt