1 void Print_Union(SqList a,SqList b) 2 { 3 int p = 0, q = 0; //初始化指针 4 int flag = -1; //记录上一次打印的元素 5 while (p!=a.length&&q!=b.length) 6 { 7 //a与b均非空时 8 if (a.data[p] > b.data[q]) 9 { 10 if (b.data[q] != flag) 11 cout << b.data[q] << endl; 12 flag = b.data[q]; //记录当前打印元素 13 q++; 14 continue; 15 } 16 if (a.data[p] < b.data[q]) 17 { 18 if (a.data[p] != flag) 19 cout << a.data[p] << endl; 20 flag = a.data[p]; 21 p++; 22 continue; 23 } 24 if (a.data[p] == b.data[q]) 25 { 26 if (a.data[p] == b.data[q]) 27 { 28 if (a.data[p] != flag) 29 cout << a.data[p] << endl; 30 flag = a.data[p]; 31 p++; 32 q++; 33 continue; 34 } 35 } 36 } 37 while (p!=a.length) 38 { 39 //打印a的剩余元素 40 if (a.data[p] != flag) 41 cout << a.data[p] << endl; 42 flag = a.data[p]; 43 p++; 44 } 45 while (q != b.length) 46 { 47 //打印b的剩余元素 48 if (b.data[q] != flag) 49 cout << b.data[q] << endl; 50 flag = b.data[q]; 51 q++; 52 } 53 }