发布网友 发布时间:2022-04-24 04:44
共1个回答
热心网友 时间:2023-10-29 08:25
void HeapCreat(SqList *s, int i, int length){
int j=2*i+1;
int temp;
while(j < length){
if(j+1<length && s->a[j]<s->a[j+1]){
j++;
}
if(s->a[i] < s->a[j]){
temp=s->a[i];
s->a[i]=s->a[j];
s->a[j]=temp;
i=j ;
j=2*i+1;
}
else{
return;
}
}
}
void HeapSort(SqList *s){
int i,temp;
for(i=s->length/2-1;i>=0;i--){
HeapCreat(s,i,len-1);
}
for(i=s->length-1;i>0;i--){
temp=s->a[i];
s->a[i]=s->a[0];
s->a[0]=temp;
HeapCreat(s,0,i-1);
}
}
热心网友 时间:2023-10-29 08:25
void HeapCreat(SqList *s, int i, int length){
int j=2*i+1;
int temp;
while(j < length){
if(j+1<length && s->a[j]<s->a[j+1]){
j++;
}
if(s->a[i] < s->a[j]){
temp=s->a[i];
s->a[i]=s->a[j];
s->a[j]=temp;
i=j ;
j=2*i+1;
}
else{
return;
}
}
}
void HeapSort(SqList *s){
int i,temp;
for(i=s->length/2-1;i>=0;i--){
HeapCreat(s,i,len-1);
}
for(i=s->length-1;i>0;i--){
temp=s->a[i];
s->a[i]=s->a[0];
s->a[0]=temp;
HeapCreat(s,0,i-1);
}
}
热心网友 时间:2023-10-29 08:25
void HeapCreat(SqList *s, int i, int length){
int j=2*i+1;
int temp;
while(j < length){
if(j+1<length && s->a[j]<s->a[j+1]){
j++;
}
if(s->a[i] < s->a[j]){
temp=s->a[i];
s->a[i]=s->a[j];
s->a[j]=temp;
i=j ;
j=2*i+1;
}
else{
return;
}
}
}
void HeapSort(SqList *s){
int i,temp;
for(i=s->length/2-1;i>=0;i--){
HeapCreat(s,i,len-1);
}
for(i=s->length-1;i>0;i--){
temp=s->a[i];
s->a[i]=s->a[0];
s->a[0]=temp;
HeapCreat(s,0,i-1);
}
}
热心网友 时间:2023-10-29 08:25
void HeapCreat(SqList *s, int i, int length){
int j=2*i+1;
int temp;
while(j < length){
if(j+1<length && s->a[j]<s->a[j+1]){
j++;
}
if(s->a[i] < s->a[j]){
temp=s->a[i];
s->a[i]=s->a[j];
s->a[j]=temp;
i=j ;
j=2*i+1;
}
else{
return;
}
}
}
void HeapSort(SqList *s){
int i,temp;
for(i=s->length/2-1;i>=0;i--){
HeapCreat(s,i,len-1);
}
for(i=s->length-1;i>0;i--){
temp=s->a[i];
s->a[i]=s->a[0];
s->a[0]=temp;
HeapCreat(s,0,i-1);
}
}
热心网友 时间:2023-10-29 08:25
void HeapCreat(SqList *s, int i, int length){
int j=2*i+1;
int temp;
while(j < length){
if(j+1<length && s->a[j]<s->a[j+1]){
j++;
}
if(s->a[i] < s->a[j]){
temp=s->a[i];
s->a[i]=s->a[j];
s->a[j]=temp;
i=j ;
j=2*i+1;
}
else{
return;
}
}
}
void HeapSort(SqList *s){
int i,temp;
for(i=s->length/2-1;i>=0;i--){
HeapCreat(s,i,len-1);
}
for(i=s->length-1;i>0;i--){
temp=s->a[i];
s->a[i]=s->a[0];
s->a[0]=temp;
HeapCreat(s,0,i-1);
}
}