
Heapsort is one of the best general-purpose sorting algorithms, a comparison sort and part of the selection sort family.
Although somewhat slower in practice on most machines than a good implementation of quicksort, it has the advantages of worst-case O(n log n) runtime. The primary advantage of the heap sort is its efficiency. The execution time efficiency of the heap sort is O(n log n). The memory efficiency of the heap sort, unlike the other O(nlogn) sorts, is constant, O(1), because the heap sort algorithm is not recursive. Heapsort is an in-place algorithm and is not a stable sort.


using namespace std;
int main()
{
int A[11],j,item,temp;
for(int i=1;i<=10;i++)
cin >> A[i];
for(int k=10;k>0;k–)
{
for(int i=1;i<=k;i++)
{
item=A[i];
j=i/2;
while(j>0 && A[j]<item)
{
A[i]=A[j];
i=j;
j=j/2;
}
A[i]=item;
}
temp=A[1];
A[1]=A[k];
A[k]=temp;
}
for(int i=1;i<=10;i++)
cout << A[i] << endl;
}



I think you meant a 0 for the declaration of “i’ and “–” at the end of the 2nd loop. Some comments and indentation would be nice to have too
might be good to explain or link to what “stable sort” means http://en.wikipedia.org/wiki/Stable_sort#Classification