Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
One of the main application of Heaps is Heap-Sort. It consists of 2 steps
(1) Build the heap and
(2) Sorted array is created by repeatedly removing the largest element (Heap is updated after each removal to maintain the heap).

Input
N
x1 x2 ……… xn
where,
N is the total numbers to be sorted
xi input numbers

Output
y1 y2 ……… yn
where array y is sorted

Heap sort function is already made available to you
You need to complete the build heap and heapify function


You need to code the following functions


// function creates and build a heap using maxHeapify
void createHeap(struct MaxHeap* maxHeap){
// Single Node is a heap
// Start from bottom most and rightmost internal node and heapify all internal nodes in bottom up way

}

// heapify a max Heap.
void heapify(struct MaxHeap* maxHeap, int idx){
// idx is the index of the node you want to heapify
}
Posted

1 solution

You have to do your own homework. Moreover just Googling you may find many many heap sort tutorials (even implementations). You starting point could be the Heapsort Wikipedia page[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900