Question
Can you please let me know if I have written the makeHeap function correctly? struct Entry { int key; char* value; }; typedef struct Entry
Can you please let me know if I have written the makeHeap function correctly?
struct Entry { int key; char* value; };
typedef struct Entry Entry;
struct Heap { int capacity; int size; Entry** elements; };
typedef struct Heap Heap;
Heap* makeHeap(int capacity) { //Make the heap Heap* theHeap = calloc(1, sizeof(Heap)); //set its capacity to param theHeap->capacity = capacity; //inital size is 0 theHeap->size = 0; //elements contains pointers (references) to Entry objects. Entry **elements[capacity]; //iterate capacity times allocating an entry reference for each element to be placed int i = 0; for(; i
theHeap->elements = *elements;
return theHeap; }
makeHeap: Should return a pointer to a newly allocated Heap with the given capacity, a size of 0, and an elements array allocated with the given capacity. The elements array should contain pointers (references) to Entry objects
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started