Program for Heap Sort in C

Here you will get program for heap sort in C.

It is a comparison based sorting technique which uses binary heap data structure.

Below I have shared simple program to implement this sorting technique in C.

Program for Heap Sort in C



Enter no. of elements:5

Enter elements:12 8 46 23 7

Array after sorting:
7 8 12 23 46

9 thoughts on “Program for Heap Sort in C”

    1. Karanjeet Singh Anand

      The time complexity of heap sort is O(nlogn) which is better than that of bubble sort which is O(n^2).

  1. I used this program but if I put number of elements in the array greater than 71, some printf lines and elements do not appear in console. Also the more I increase the size of the array the less lines and elements appear in console while the program is running.. What is going on? Does this code have a limit as to how many elements you can use?

      1. That’s the thing. I scroll way up at the beginning and I notice that a) some printf lines are not printed in console and b) when the sorting ends, not all elements are shown in console, even though if I “fprintf” them into a data.dat I can see all the elements.

        1. I think I know the problem. Because I use 10000 elements or more, the cmd window cant print so many lines it has a 9999 limit and you have to set that too by yourself. the default is like 100 or something. That’s why some of my printf lines magically dissapeared. There was not enough space for them to be printed out in the cmd window.

    1. Shatakshi Kashyap

      Dwnadjst is actually the sink fuction,the input we gave taken is unsortedbso wif parent<child value parent has to move dwn (Sink) and the child tets promoted that is why we perfem sink,arter one sink we get the highet elem at a[0]

Leave a Comment

Your email address will not be published. Required fields are marked *