Question

Based on the preconditions, did i coded this function correctly in c++? /* Creates an array...

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;
}

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Based on the preconditions, did i coded this function correctly in c++? /* Creates an array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Here is the indexOf method that I wrote: public static int indexOf(char[] arr, char ch) {...

    Here is the indexOf method that I wrote: public static int indexOf(char[] arr, char ch) {            if(arr == null || arr.length == 0) {                return -1;            }            for (int i = 0; i < arr.length; i++) {                if(arr[i] == ch) {                    return i;                }            }        return -1;       ...

  • Can someone help me with the writing of this code please? public static int promptInt(Scanner input,...

    Can someone help me with the writing of this code please? public static int promptInt(Scanner input, String prompt, int min, int max) { return 0; //TODO replace }    /**    * Returns the index within arr of the first occurrence of the specified character.    * If arr is null or 0 length then return -1. For all arrays, don't assume a length    * but use the array .length attribute.    * @param arr The array to look...

  • I am failing one of the tests cases for the trimArray function. The test that my...

    I am failing one of the tests cases for the trimArray function. The test that my function is failing is testing that when you get a toTrim array of  " ", it should return "" (an array of no characters). How do I incorporate that functionality into the function and where will it go in the C++ code? Here's my function: // The function trimArray() is given a pointer to a character array that // is NULL terminated called toTrim. This...

  • import java.util.Arrays; import java.util.Random; import java.util.Scanner; /** * TODO Write a summary of the role of...

    import java.util.Arrays; import java.util.Random; import java.util.Scanner; /** * TODO Write a summary of the role of this class in the * MasterMind program. * * @author TODO add your name here */ public class MasterMind { /** * Prompts the user for a value by displaying prompt. * Note: This method should not add a new line to the output of prompt. * * After prompting the user, the method will consume an entire * line of input while reading...

  • Can you help me make these two methods listed below work? I have code written but...

    Can you help me make these two methods listed below work? I have code written but it is not working. I would appreciate any advice or help. Function "isAPalidrome" accepts an array of characters and returns an integer. You must use pointer operations only, no arrays. This function should return 1 (true) if the parameter 'string' is a palindrome, or 0 (false) if 'string' is not a palindrome. A palindrome is a sequence of characters which when reversed, is the...

  • Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2...

    Problem with C++ program. Visual Studio say when I try to debug "Run-Time Check Failure #2 - Stack around the variable 'string4b' was corrupted. I need some help because if the arrays for string4a and string4b have different sizes. Also if I put different sizes in string3a and string4b it will say that those arrays for 3a and 3b are corrupted. But for the assigment I need to put arrays of different sizes so that they can do their work...

  •    /**    * Returns an array of booleans that are set true or    *...

       /**    * Returns an array of booleans that are set true or    * false based on the associated values in the array    * arr using the following rules:    * 1. If arr[i] is divisible by three then the boolean    * value in the the array returned at the same position    * should be true    * 2. Unless the values in arr[i] is also divisible by 5,    * then the value returned...

  • In C Programming Language In this lab you will implement 4 string functions, two using array...

    In C Programming Language In this lab you will implement 4 string functions, two using array notation and two using pointers. The functions must have the signatures given below. You may not use any C library string functions. The functions are 1. int my strlen (char s ) - This function returns the number of characters in a string. You should use array notation for this function. 2. int my strcpy (char s [], char t I)- This function overwrites...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • Create an ArrayListReview class with one generic type to do the following • Creates an array...

    Create an ArrayListReview class with one generic type to do the following • Creates an array list filled with the generic type of the ArrayListReview class, and inserts new elements into the specified location index-i in the list. (5 points) • Create a method inside the class to implement the calculation of Fibonacci numbers. Use System.nanoTime to find out how much time it takes to get fab(50). Create a method inside the class to check if an array list is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT