Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

implement an in-place heap sort program ruby. The program should have a function

ID: 644904 • Letter: I

Question

implement an in-place heap sort program ruby. The program
should have a function/procedure/subroutine that will do the main work. That is, to accept a list/array (or anything appropriate) of integers and then sort it using the in-place heap sort algorithm. The heap sort
algorithm requires converting the list/array into a heap. Once the list/array is converted into a heap, you
need to print out the heap in tree-format as a string before continuing. This function/procedure/subroutine
should return the sorted list/array and the string if possible.
let the sorted list/array to be return via

Explanation / Answer

#include
#include
void main()
{int arr[100],I,n;

clrscr();
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&arr[i]);
}
printf(" entered list are as follows");
for(i=1;i<=n;i++)
{
printf(" %d",arr[i]);
}

Heap(n,arr);

}
void Heap(int n, int l[])

{
int i,v,p,k,t,j;
/*creation of heap*/
for(k=2;k<=n;k++)
{
i=k;
t=l[k];
j=i/2;
while((i>1)&&(t > l[j]))
{
l[i]=l[j];
i=j;
j=i/2;
if(j<1)
j=1;
}
l[i]=t;
}



printf(" HEAP");


for(i=1;i<=n;i++)
{
printf(" %d",l[i]);
}
printf(" ");
//heapsort
for(k=n;k>=2;--k)
{
t=l[1];
l[1]=l[k];
l[k]=t;
i=1;
v=l[1];
j=2;
if((j+1)
if(l[j+1]>l[j])
j++;
while((j<=(k-1))&&(l[j]>v))
{
l[i]=l[j];
i=j;
j=2*i;
if((j+1)
if(l[j+1]>l[j])
j++;
else
if(j>n)
j=n;
l[i]=v;
}
for(p=1;p<=n;p++)
{
printf(" %d",l[p]);
}
printf(" ");
}
printf(" the sorted list ");
for(i=1;i<=n;i++)
{
printf(" %d",l[i]);
}
getch();

}