int *hsort(int data[],int sz){ int i; int *s = malloc(sizeof(int)*sz); BHeap *heap = bheap_create(); for(i = 0; i < sz ; i++) heap = bheap_insert(heap,data[i]); // bheap_print(heap); i = 0; while(!bheap_is_empty(heap)) { s[i++] = bheap_minimum(heap); heap = bheap_erase_minimum(heap); } bheap_destroy(heap); return s; }
int *hsort2(int data[],int sz){ int i; int *s = malloc(sizeof(int)*sz); BHeap *heap = bheap_create(); for(i = 0; i < sz ; i++) heap = bheap_insert(heap,data[i]); bheap_print(heap); /* for(i = 0; i < sz ; i++){ s[i]= bheap_minimum(heap); heap = bheap_erase_minimum(heap) } */ for(i = 0; heap->nelems != 0; i++) { s[i] = bheap_minimum(heap); heap = bheap_erase_minimum(heap); } bheap_destroy(heap); return s; }
int main(void) { bheap_t bh; bheap_init(&bh,10,cmp); long long *arr = malloc(sizeof(long long)*1024*1024*4); long long i; for(i=0;i<1024*1024*4;i++) { arr[i]=1024*1024*4-i; bheap_insert(&bh,&arr[i]); } while(bheap_get_size(&bh) > 0) { long long *head = bheap_remove(&bh); printf("poped: %lld\n",*head); } free(arr); bheap_destroy(&bh); return 0; }
void array_to_heap(BHeap *heap,int *data,int sz){ int i; for(i = 0; i < sz ; i++) heap = bheap_insert(heap,data[i]); }
static void __pfair_add_release(struct task_struct* t, struct bheap* queue) { bheap_insert(pfair_ready_order, queue, tsk_rt(t)->heap_node); }