I am trying to remove all duplicates in an array of c++ strings. I have code but it is causing my program to do nothing.
int removeDups(string a[], int n)
{
if (n < 0)
{
return -1;
}
int k = 0;
int retained = 0;
while (k<n)
{
if (a[k] == a[k + 1])
{
for (int j = k+1; j < (n-k); j++)
{
a[j] = a[j + 1];
}
}
else
{
retained++;
k++;
}
}
return retained;
}
the function is supposed to consider the first n items in the array, remove any consecutive duplicates, and return the number of unique items retained (out of the the first n items in the array). I cannot used vectors or any fancy stuff.
sizeofdoesn't do what you think it does.std::unique?