Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Based on the preconditions, did i coded this function correctly in c++? /* Creat

ID: 3692822 • Letter: B

Question

Based on the preconditions, did i coded this function correctly in c++?

/*
Creates an array of HuffmanNodes (more specifically, pointers to HuffmanNodes)
based on the given character-frequency pairs.

characters: an array of char
frequencies: an array of int
length: the length of characters and frequencies arrays

returns: an array of HuffmanNode*

Note: For 0 <= i < length, the frequency of the character characters[i]
is found at frequencies[i].
*/
HuffmanNode **genHuffmanNodes(char *characters, int *frequencies, int length)
{
// TODO
HuffmanNode* arr[length];

for (int i = 0;i < length; i++)
{
arr[i]->character = characters[i];
arr[i]->frequency = frequencies[i];
}

return arr;
return NULL;
}

Explanation / Answer

yes it was correct but it will be better if you allocate memory rather than static allocation which was quite helpful and appropriate

   besides that everything is correct ,,,,.....