-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp2.cpp
More file actions
44 lines (36 loc) · 893 Bytes
/
Copy pathp2.cpp
File metadata and controls
44 lines (36 loc) · 893 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "ADTList.cpp"
template<typename T>
void Union(T &a,T &b){
auto j=b.begin();
for(auto i=a.begin();i!=a.end();++i)
for(;j!=b.end() and *i<=*j;++j)
if(*i<*j)
i=a.insert(i,*j);
for(;j!=b.end();++j)
a.insert(a.end(),*j);
}
int main(){
int a; cin>>a;
SquList<int> list11(a);
LinkList<int> list21;
for(int i=0,x;i<a;i++){
cin>>x;
list21.push_back(x);
list11.setElem(i,x);
}
int b; cin>>b;
SquList<int> list12(b);
LinkList<int> list22;
for(int i=0,x;i<b;i++){
cin>>x;
list22.push_back(x);
list12.setElem(i,x);
}
cout<<"SeqList:"<<endl;
Union(list11,list12);
cout<<"After merge(): "; list11.traverse();
cout<<"LinkList:"<<endl;
Union(list21,list22);
cout<<"After merge(): "; list21.traverse();
return 0;
}