Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 6d9bbbae0c
Fetching contributors…

Cannot retrieve contributors at this time

48 lines (33 sloc) 0.668 kB
#include "heap.h"
#include <stdio.h>
int cmpfunc(vector_p heap, int i, int j){
int * iVal;
int * jVal;
iVal = (int*)vector_get(heap, i);
jVal = (int*)vector_get(heap, j);
return (*iVal) - (*jVal);
}
void print_heap(vector_p heap){
int i;
int * iVal;
for(i=0; i<heap->length; i++){
iVal = (int*)vector_get(heap, i);
printf("%d, ", *iVal);
}
printf("\n");
}
int main(void){
heap_p hp = create_heap(cmpfunc);
int i;
for(i=0; i<8; i++){
vector_add(hp->vec, &i, sizeof(int));
}
build_heap(hp);
for(i=8; i<10; i++){
heap_insert(hp, &i, sizeof(int));
}
heap_remove(hp);
print_heap(hp->vec);
destroy_heap(hp);
return 0;
}
Jump to Line
Something went wrong with that request. Please try again.