I have an char array, that has some duplicate values:
A B C D E F E A
And this is my algorithm to remove the duplicate values:
char array[20] = {'A', 'B', 'C', 'D', 'E', 'F', 'E', 'A'};
int length = 8;
for (int i = 0; i < length; i++)
{
for (int j = i + 1; j < length - 1; j++)
{
if (array[i] == array[j])
{
array[j] = array[j + 1];
length--;
}
}
}
EXPECTED OUTPUT: A B C D E F
OUTPUT: A B C D E F A
I have tried to run this algorithm on papers, it seems okay when I do this in writing, however it doesn't work in my application.
counteris the result length.a[j] == a[i]you now havea[j] == a[j+1]. Always