Question: #include #include void mysort ( int * myarray ) ; int main ( ) { int n = 1 0 ; int * arr =

#include
#include
void mysort(int* myarray);
int main(){
int n =10;
int *arr =(int *)malloc(n * sizeof(int));
if (arr == NULL){
printf("Memory not allocated.
");
return 1;
}
arr[0]=4;
arr[1]=2;
arr[2]=9;
arr[3]=6;
arr[4]=1;
arr[5]=3;
arr[6]=8;
arr[7]=0;
arr[8]=5;
arr[9]=7;
int i =0;
mysort(arr);
for(;i < n;i++){
printf("%d",arr[i]);
}
free(arr);
return 0;
}
void mysort(int* myarray){
for(int j =9;j>=1;j--){
for(int i = j; i >0; i--){
int k =(i-1)/2;
if (myarray[i]> myarray[k]){
int temp = myarray[i];
myarray[i]= myarray[k];
myarray[k]= temp;}
}
int temp2= myarray[j];
myarray[j]= myarray[0];
myarray[0]= temp2;
}
}
why my code isnt exacly heap sort, it gives absolutely correct values in almost every value, if it is not heap sort what it is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!