C语言编程 填空题
函数HeapSort与HeapCreat实现堆排序操作,请在空格处将算法补充完整。typedefstructlist{inta[MAXSIZE];intlength;}S...
函数HeapSort与HeapCreat实现堆排序操作,请在空格处将算法补充完整。
typedef struct list{
int a[MAXSIZE];
int length;
} SqList;
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]){
_____________________________ ;
}
if(s->a[i] < s->a[j]){
temp=s->a[i];
s->a[i]=s->a[j];
s->a[j]=temp;
___________________ ;
__________________ ;
}
else{
______________________ ;
}
}
}
void HeapSort(SqList *s){
int i,temp;
for(i=s->length/2-1;i>=0;i--){
_________________ ;
}
for(i=s->length-1;i>0;i--){
temp=s->a[i];
_________________ ;
___________________ ;
___________________ ;
}
} 展开
typedef struct list{
int a[MAXSIZE];
int length;
} SqList;
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]){
_____________________________ ;
}
if(s->a[i] < s->a[j]){
temp=s->a[i];
s->a[i]=s->a[j];
s->a[j]=temp;
___________________ ;
__________________ ;
}
else{
______________________ ;
}
}
}
void HeapSort(SqList *s){
int i,temp;
for(i=s->length/2-1;i>=0;i--){
_________________ ;
}
for(i=s->length-1;i>0;i--){
temp=s->a[i];
_________________ ;
___________________ ;
___________________ ;
}
} 展开
1个回答
展开全部
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);
}
}
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);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询