extractMin 的参数行出现以下错误:
randmst.c:129: 错误:在“&”标记之前需要“;”、“,”或“)”
如果我没有粘贴足够的代码导致错误明显,请告诉我。
//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;
}
最佳答案
你不能在 C
中执行此 extractMin(VertexPointer *heap, int &heap_size)
- 将其更改为 extractMin(VertexPointer *heap, int *heap_size)
C 中没有传递引用。所以你应该有这样的东西:
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;
}
&
用于获取变量的地址,因此在调用函数时应这样调用:
extractMin(someAddress_to_heap, someAddress_to_heap_size)
关于c - 我需要在符号前放什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22242292/