-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp3.cpp
More file actions
39 lines (33 loc) · 876 Bytes
/
Copy pathp3.cpp
File metadata and controls
39 lines (33 loc) · 876 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
#include "ADTList.cpp"
template<typename T>
void unique(T *list){
for(auto i=list->begin();i!=list->end();++i){
auto j=i; ++j;
while(j!=list->end()){
//cerr<<(*i)<<" cmp "<<(*j)<<endl;
if(*i==*j)
j=list->erase(j);
else
++j;
}
}
}
int main(){
int n; cin>>n;
SquList<int> *list1=new SquList<int>(n);
LinkList<int> *list2=new LinkList<int>;
for(int i=0,x;i<n;i++){
cin>>x;
list2->push_back(x);
list1->setElem(i,x);
}
cout<<"SeqList:"<<endl;
cout<<"Before unique(): "; list1->traverse();
unique(list1);
cout<<"After unique(): "; list1->traverse();
cout<<"LinkList:"<<endl;
cout<<"Before unique(): "; list2->traverse();
unique(list2);
cout<<"After unique(): "; list2->traverse();
return 0;
}