Question: Write a C program, based on the pseudocode in the textbook, implementing heap-sort. Use as input a 12-long array of randomly generated integers and give
Write a C program, based on the pseudocode in the textbook, implementing heap-sort. Use as input a 12-long array of randomly generated integers and give as as output (i) the original random array (ii) the intermediate step where the array is made into a heap and (iii) the final sorted array.
pseudocode in the book:
HEAPSORT.A/ 1 BUILD-MAX-HEAP.A/ 2 for i D A:length downto 2 3 exchange AOE1 with AOEi 4 A:heap-size D A:heap-size 1 5 MAX-HEAPIFY.A; 1/
BUILD-MAX-HEAP.A/ 1 A:heap-size D A:length 2 for i D bA:length=2c downto 1 3 MAX-HEAPIFY.A; i /
MAX-HEAPIFY.A; i / 1 l D LEFT.i / 2 r D RIGHT.i / 3 if l A:heap-size and AOEl > AOEi 4 largest D l 5 else largest D i 6 if r A:heap-size and AOEr > AOElargest 7 largest D r 8 if largest i 9 exchange AOEi with AOElargest 10 MAX-HEAPIFY.A; largest/
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
