int main() { initializeHeap(heap); initializeValues(); buildMaxHeap(); printValues(); //printf("max: %d \n",heapExtractMax()); //heapIncreaseKey(2,18); //maxHeapInsert(17); printValues(); return 0; }
int main() { initializeHeap(heap); initializeValues(); buildMinHeap(); printValues(); //printf("min: %d \n",heapExtractMin()); //heapDecreaseKey(2,0); //minHeapInsert(0); //printValues(); return 0; }
heap *heapSort(int *array, int size){ heap *h = initializeHeap(array,size); int index = 0; //printf("~~~~~~~ Heap built ~~~~~~~\n"); //printArray(h->heap,10); for(index = h->size-1; index >= 0; index--){ int temp = h->heap[index]; //printf("Exchanging %d (at %d) for %d\n",temp,index,h->heap[0]); h->heap[index] = h->heap[0]; h->heap[0] = temp; h->size -= 1; max_heapify(h,0); //printf("Heap size gone to: %d\n",h->size); //printArray(h->heap,10); } return h; }
void *allocateMemory(unsigned size_in_bytes) { int size; unsigned chunk; int chunk_size; if (!initialized) { initializeHeap(); initialized = true; } if (size_in_bytes == 0) { return nullptr; } size = (size_in_bytes + sizeof(int)-1) / sizeof(int); chunk = findFreeChunk(size); if (always_false) { displayChunks(); } if (chunk == bogus_chunk) { printf("Ah NUTS, out of memory\n"); exit(-1); // forces main to return -1 !immediately! } splitChunkIfNecessary(chunk, size); chunk_size = memory_pool[chunk]; assert(chunk_size >= size); // just a sanity check, pretty insane really setBothSignatures(chunk, -chunk_size); /* OK, all done... all we need to do now is return... oh, * we're supposed to return a pointer, not an index..... */ return &memory_pool[chunk + 1]; }
void initializeKernelHeap() { initializeHeap(&kernel_heap, KERNEL_HEAP_ADDR); }