Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

Why are the productivity important?

Answered: 1 week ago

Question

5-3. What functions do headings serve? [LO-2]

Answered: 1 week ago