-
-
Save teldridge11/50949494f1a07f84519653b1b456a334 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void dyHeapRemoveMin(DynamicArray* heap, compareFunction compare) | |
{ | |
// FIXME: implement | |
int last = dySize(heap)-1; | |
assert (last != 0); /* make sure we have at least one element */ | |
/* Copy the last element to the first position */ | |
dyPut(heap, dyGet(heap, last), 0); | |
dyRemoveAt(heap, last); /* Remove last element.*/ | |
adjustHeap(heap, last, 0, compare);/* Rebuild heap */ | |
} | |
/** | |
* Returns the first element, which has the min priority, from the heap. | |
* @param heap | |
* @return Element at the top of the heap. | |
*/ | |
TYPE dyHeapGetMin(DynamicArray* heap) | |
{ | |
// FIXME: implement | |
return heap->data[0]; | |
} |
int indexSmallest (DynamicArray *v, int i, int j, compareFunction compare)
{
if(compare(dyGet(v,i), dyGet(v, j)) <=0)
{
return i;
}
else return j;
}
assert(heap != 0); int last; assert(dySize(heap) > 0); last = dySize(heap)-1; dyPut(heap, dyGet(heap,last), 0); dyRemoveAt(heap, last); adjustHeap(heap, last, 0, compare);
if(dySize(list) >0)
{
printf("Printing list...\n");
listPrint(list);
}
else
{
printf("List is empty");
}
break;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
int indexSmallest = compare(dyGet(heap, leftIdx), dyGet(heap, rightIdx)) == -1 ? leftIdx : rightIdx;