Hello;
I would like to compress an 1D array of arbitrary number of elements. For instance if a user inputs
IN : 111122233331
OUT: 14233411
[it shrinks/increases the array and replaces all the identical consecutive elements with a number of how many times theyve appeared.]
This task must be accomplished without using a second backup array. So. I was thinking if I could do something like this :
for(j=i-1,k=(i*2)-1;j>=0;j--,k-=2)
{
i++;
arr[k-1]=arr[j];
arr[k]=0;
}
What this does is makes a space between the elements and marks it with zero. So my output after this point is:
IN : 11223331
OUT :1010202030303010
So my numbers are on j%2==0 indexes, and zero-flagged holes are on j%2!=0 indexes. Well now im stuck. I still need to count the numbers on even indexes and shrink the array. Any hints? Thank you very much guys :)