Hello!
Well, there is nothing complicated in doing this. You want to use a single for loop,
then here is the strategy:
- What will happen is that the first time you encounter a repetition, you have
to move all the subsequent bytes by one to the left. The second time, you will
have to move by 2 to the left.
There are many ways to do it. I would use two indexes to the same array.
At fist, index_out = 0, and index_in = 1.
If the bytes at the 2 indexes are equal, then you have to move index_in by one,
and not move index_out.
If they are not equal, then you copy the value of index_in into index_out and you move
both.
Let's try with the example above. I will replace the numbers with letters to avoid
confusion
1st line: position of the pointers
2nd line array
The first 2 characters are not equal, therefore write the second on input pointer+1
0 1
A B B D G E E
Move the pointers by 1 since it was different
1 2
A B B D G E E
The characters 1 and 2 are equal. Therefore move the 3 only and don't write anything
1 3
A B B D G E E
Then the characters 1 and 3 are different. Write character at 3 to output pointer +1
and move both
2 4
A B D D G E E
the characters 2 and 4 are different. Write character at 3 to output pointer +1
and move both.
3 5
A B D G G E E
the characters 3 and 5 are different. Write character at 4 to output pointer +1
and move both.
4 6
A B D G E E E
Pointers of 4 and 6 are equal. and 6 is at the end. You can also remove the
characters after the end of the output pointer.
NB : I didn't try the algorithm, but I would try this way. Note that you should
think about that yourself...
Dora.