-
-
Save yiyizheliu/32263f3957b43f013fbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Suppose the list is a known one. This function is to delete the duplicate elements in the list. I use a vector here to deal | |
with the deleting part. | |
*/ | |
list deleteDup(list list1) | |
{ | |
vector<int> ori_list; | |
int flag=0,i=0; | |
int inp1; | |
list<int>::iterator copytovec; | |
//change the list into a vector to process | |
ori_list.resize(list1.size()); | |
for(copytovec=list1.begin();copytovec!=list1.end();copytovec++) | |
{ | |
ori_list[i]=*copytovec; | |
i++; | |
} | |
//from the bottom to the beginning, check if there is the duplicate one | |
for(int i=ori_list.size()-1;i>=0;i--) | |
{ | |
for(int j=0;j<i;j++) | |
{ | |
if(ori_list[i]==ori_list[j]) | |
{ | |
flag=1; | |
break; | |
} | |
} | |
if(flag==1) | |
{ | |
ori_list.erase(ori_list.begin()+i); | |
flag=0; | |
} | |
} | |
list1.clear(); | |
for(int i=0;i<ori_list,size();i++) | |
{ | |
list1.push_back(ori_list); | |
} | |
return list1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment