This will remove duplicates even if there is multiple in a row like this
Again note that this is for pairs
And only the first instance is kept.
Lets say vector input; has the following
bob
son
bob
son2
mark
wife1
mark
wife2
mark
wife3
Becomes
bob
son
mark
wife
This will remove duplicates up to 6 in a row, increase as needed.
I had to remove the blank spaces two times for some reason.
//vector<string> input; is filled in alphabetical order with duplicates
int size=input.size();
//transfer to dynamically created array of strings
string *strarray;
strarray = new string[size];
for(int i=0; i<size; i++){
strarray[i] = input[i];//Copy the vector to the string
}
// erase duplicates
for (int i=0; i<=size-(size/2); i+=2){
if (strarray[i]==strarray[i+2])
{
strarray[i+2].erase(0,strarray[i+2].size());
strarray[i+3].erase(0,strarray[i+3].size());
}
if (strarray[i]==strarray[i+4])
{
strarray[i+4].erase(0,strarray[i+4].size());
strarray[i+5].erase(0,strarray[i+5].size());
}
if (strarray[i]==strarray[i+6])
{
strarray[i+6].erase(0,strarray[i+6].size());
strarray[i+7].erase(0,strarray[i+7].size());
}
if (strarray[i]==strarray[i+8])
{
strarray[i+8].erase(0,strarray[i+8].size());
strarray[i+9].erase(0,strarray[i+9].size());
}
if (strarray[i]==strarray[i+10])
{
strarray[i+10].erase(0,strarray[i+10].size());
strarray[i+11].erase(0,strarray[i+11].size());
}
}
// remove blank components
for (int i=0; i<size; i++){
if (strarray[i]=="") {
for (int j=i; j<size-1; j++)
strarray[j]=strarray[j+1];
size--;
i--;
}
}