哟。我有这个非常简单的交换功能,似乎不起作用。可能是一个指针问题,所以任何建议都会很好。
void swap(pQueue *h, int index1, int index2) {
student *temp = &h->heaparray[index1];
h->heaparray[index1] = h->heaparray[index2];
h->heaparray[index2] = *temp;
}
pQueue是一个堆指针,index1并且index2保证是有效的索引。
student *temp确实得到了的值,heaparray[index1]但是当heaparray[index2]被分配临时值时,heaparray[index2]保持不变。任何建议表示赞赏。