
1 #include<stdio.h> 2 typedef struct{ 3 int element[50]; 4 int length; 5 }SeqList; 6 CreateSeqList(SeqList*S) 7 { 8 scanf("%d",&S->length); 9 for(int i=0;i<S->length;i++) 10 scanf("%d",&S->element[i]); 11 } 12 Delete(SeqList*A,SeqList*B,SeqList*C)//算法时间复杂度为 O(n) 13 { 14 int a=0,b=0,c=0,p=0,pre,follow; 15 SeqList position; 16 while(a<A->length&&b<B->length&&c<C->length) 17 { 18 while(b<B->length&&B->element[b]<A->element[a])b++; 19 while(c<C->length&&C->element[c]<A->element[a])c++; 20 if(A->element[a]==B->element[b]&&B->element[b]==C->element[c]) 21 position.element[p++]=a;//用position数组记录待删元素下标 22 a++; 23 } 24 position.element[p]=A->length; 25 position.length=p;//控制下面的while循环结束 26 for(p=0;p<position.length;p++) 27 { 28 pre=position.element[p]-p; 29 follow=position.element[p]+1; 30 while(follow<position.element[p+1]) 31 A->element[pre++]=A->element[follow++]; 32 } 33 34 A->length=A->length-position.length; 35 } 36 Order(SeqList*A) 37 { 38 for(int i=0;i<A->length;i++) 39 printf("%d ",A->element[i]); 40 } 41 int main() 42 { 43 SeqList A,B,C; 44 CreateSeqList(&A),CreateSeqList(&B),CreateSeqList(&C); 45 Delete(&A,&B,&C); 46 Order(&A); 47 return 0; 48 }