Question

Getting the following error for the argument line of extractMin:

randmst.c:129: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token

Let me know if I didn't paste enough code for the error to be obvious.

//the heap functions

//based on p. 163 of clrs
VertexPointer
extractMin(VertexPointer *heap, int &heap_size){
    VertexPointer max = heap[0];
    (*heap[0]).key = 100;
    heap_size = heap_size - 1;
    minHeapify(heap, heap_size, 1);
    return max;
}
Was it helpful?

Solution

You cannot do this extractMin(VertexPointer *heap, int &heap_size) in C - change it to extractMin(VertexPointer *heap, int *heap_size)

There is no Pass-by-reference in C. So you should have something like this:

extractMin(VertexPointer *heap, int *heap_size){
    VertexPointer max = heap[0];
    (*heap[0]).key = 100;
    *heap_size = *heap_size - 1;
    minHeapify(heap, *heap_size, 1); 
    return max;
}

The & is used to get the address of the variable so when calling the function you should call it this way:

extractMin(someAddress_to_heap, someAddress_to_heap_size)

OTHER TIPS

Passing by refrence doesnt work in C, there is a difference in passing by refrence and passing by address. C++ support passing by refrence but C doesnt. Change your code to

VertexPointer
extractMin(VertexPointer *heap, int *heap_size)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top