Skip to content

Instantly share code, notes, and snippets.

@teldridge11
Last active May 20, 2016 18:19
Show Gist options
  • Save teldridge11/50949494f1a07f84519653b1b456a334 to your computer and use it in GitHub Desktop.
Save teldridge11/50949494f1a07f84519653b1b456a334 to your computer and use it in GitHub Desktop.
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];
}
@gregmankes
Copy link

gregmankes commented May 20, 2016

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);

@alaquitara
Copy link

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