将两个有序顺序表/链表合并 成一个(差集)
A: 1,2,3,4,5
B:2,4,6,9
C=A-B:1,3,5;
类似归并排序,改一改就行
#include <cstdio>
#include <cstdlib>
/**********************PART1***************************/
struct Sqlist {
int *num;
int len;
}A,B;
Sqlist Dif(Sqlist A,Sqlist B) { //A-B
int i = 0,j = 0;
Sqlist C;
C.len = 0;
C.num = (int *)malloc(sizeof(int)*A.len);
while (i < A.len && j < B.len) {
while (j < B.len && B.num[j] < A.num[i]) j++;
while (i < A.len && j < B.len && A.num[i] < B.num[j]) C.num[C.len++] = A.num[i++];
while (i < A.len && j < B.len && A.num[i] == B.num[j]) i++;
}
while (i < A.len) C.num[C.len++] = A.num[i++];
return C;
}
void WorkSqlist() {
int i;
puts("Input A:");
scanf("%d",&am