Move to Front Encoding and Decoding

int MTFSearch(int character, int *alphabet, int alphabetSize)
{
int result = -1;
for(int i = 0; i < alphabetSize; i++)
{
if(character == alphabet[i])
{
result = i;
break;
}
}
return result;
}
void MoveToFront(int character, int index, int *alphabet, int alphabetSize)
{
int temp = 0;
int *copy =malloc(alphabetSize * sizeof(int));
for(int i = 0; i < alphabetSize; i++)
{
copy[i] = alphabet[i];
}
for(int i = 0; i < alphabetSize-1; i++)
{
if(i < index)
{
alphabet[i+1] = copy[i];
}
}
alphabet[0] = character;
}
void MoveToFrontDecode(int index, int *alphabet, int alphabetSize)
{
int temp = 0;
int *copy =malloc(alphabetSize * sizeof(int));
for(int i = 0; i < alphabetSize; i++)
{
copy[i] = alphabet[i];
}
for(int i = 0; i < alphabetSize-1; i++)
{
if(i < index)
{
alphabet[i+1] = copy[i];
}
}
alphabet[0] = copy[index];
}
void MTFEncode(int *array, int arrayLength, int alphabetSize)
{
int index = 0;
int *alphabet = malloc(alphabetSize * sizeof(int));
for(int i = 0; i < alphabetSize; i++)
{
alphabet[i] = i;
}
for(int i = 0; i < arrayLength; i++)
{
index = MTFSearch(array[i], alphabet,alphabetSize);
if(index == -1)
{
printf("\n%d Not in alphabet\n",array[i]);
break;
}
printf("%d,", index);
MoveToFront(array[i],index, alphabet,alphabetSize);
//PrintArrayCompress(alphabet, alphabetSize);
}
}
void MTFDecode(int *array, int arrayLength, int alphabetSize)
{
int index = 0;
int *alphabet = malloc(alphabetSize * sizeof(int));
for(int i = 0; i < alphabetSize; i++)
{
alphabet[i] = i+1;
}
for(int i = 0; i < arrayLength; i++)
{
printf("%d,", alphabet[array[i]]);
MoveToFrontDecode(array[i],alphabet,alphabetSize);
}
}
/*
int main()
{
int array[] = {0,0,0,0,0,0,1,0,0,0,3,1,3,3,3,3,1,1,3,3,2,2,3,1,};
int size = sizeof(array)/sizeof(int);
//BuildNgram(array, 5,3);
int array2[] = {1,1,1,1,1,1,2,1,1,1,4,2,3,3,3,3,1,1,3,3,2,2,3,1,};
MTFEncode(array, size, 35);
printf("\nDecode \n");
MTFDecode(array2, size, 35);
return 0;
}*/

I got my first job at 17. I got my first programming job at 18. I think I’m burnt out at 20.