int main(int argc, char * argv[]) { heap_t* h2 = makeSampleHeap(2); printHeap(h2, 2); buildMaxHeap(h2, 2); printf("< After Heapify >\n"); printHeap(h2, 2); heapSort(h2, 2); printf("< After Heap Sort >\n"); printHeap(h2, 2); releaseHeap(h2); printf("\n"); heap_t* h3 = makeSampleHeap(3); printHeap(h3, 3); buildMaxHeap(h3, 3); printf("< After Heapify >\n"); printHeap(h3, 3); printf("Extract Max = %d\n", heapExtractMax(h3)); printf("< After Extracting Max >\n"); printHeap(h3, 2); maxHeapInsert(h3, 8); printf("After Inserting key = %d >\n", 8); printHeap(h3, 3); releaseHeap(h3); printf("\n"); heap_t* h4 = makeSampleHeap(4); printHeap(h4, 4); buildMaxHeap(h4, 4); printf("< After Heapify >\n"); printHeap(h4, 4); heapSort(h4, 4); printf("< After Heap Sort >\n"); printHeap(h4, 4); releaseHeap(h4); printf("\n"); heap_t* h5 = makeSampleHeap(5); printHeap(h5, 5); buildMaxHeap(h5, 5); printf("< After Heapify >\n"); printHeap(h5, 5); printf("Extract Max = %d\n", heapExtractMax(h5)); printf("< After Extracting Max >\n"); printHeap(h5, 4); maxHeapInsert(h5, 12); printf("< After Inserting key = %d >\n", 12); printHeap(h5, 5); releaseHeap(h5); printf("\n"); }
int main() { int max = 0; heap[0] = 10; heap[1] = 1; heap[2] = 2; heap[3] = 3; heap[4] = 4; heap[5] = 7; heap[6] = 8; heap[7] = 9; heap[8] = 10; heap[9] = 14; heap[10] = 16; printf("Original State:\n"); printHeap(heap); buildMaxHeap(heap); printf("\n After Heapifying:\n"); printHeap(heap); heapIncreaseKey(heap, 9, 15); printf("\n After Increasing S[9]'s key to 15:\n"); printHeap(heap); max = heapExtractMax(heap); printf("\n Max key is %d, After Extracting Max Key:\n", max); printHeap(heap); maxHeapInsert(heap, 13); printf("\n After inserting key 13:\n"); printHeap(heap); return 0; }