我需要在中合并K个有序列表O(n*logk)
。我正在尝试创建一个列表数组,但我不知道如何调用某些函数(如min_heapify)。
void min_heapify(List *list[],int size);
void main() {
List list[10]; // initialize all 10 list randomly in ascending order.
min_heapify(&list,10); // This line won't compile.
}
请帮忙。
您正在传递指向数组的指针,而不是传递函数期望的指针数组。
您的函数需要一个列表指针数组,因为它既有星号又有一对括号:
List *list[] // <<== This means "an array of pointers to elements of type List"
要向该函数传递一个指针数组,请在中声明一个指针数组main
,然后进行调用:
void main() {
List *list[10];
// intitialize all 10 list pointers randomly in ascending order.
for (int i = 0 ; i != 10 ; i++) {
list[i] = malloc(...); // Initialize list at position i
}
min_heapify(list,10); // Remove the ampersand
}
如果要传递列表列表,请仅保留星号或方括号:
void min_heapify(List list[],int size);
或同等学历
void min_heapify(List *list,int size);
从的调用中删除“&”号,main
以正确进行编译:
void main() {
List list[10]; // intitialize all 10 lists randomly in ascending order.
min_heapify(list,10); // Remove the ampersand
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句