Yo. I have this extremely simple swap function that seems to not work. Probably a pointer issue so any advice would be nice.
void swap(pQueue *h, int index1, int index2) {
student *temp = &h->heaparray[index1];
h->heaparray[index1] = h->heaparray[index2];
h->heaparray[index2] = *temp;
}
pQueue is a heap pointer, index1 and index2 are guaranteed to be valid indices.
student *temp does get the value of heaparray[index1] but when heaparray[index2] is assigned the temp value, the heaparray[index2] stays the same. Any advice appreciated.
You need to copy the actual value of
h->heaparray[index1](not its address) intotempand then later copy that value intoh->heaparray[index2], like so: