标题:[求助]内排序的死循环~!~!~!~
取消只看楼主
sailer
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2005-10-12
 问题点数:0 回复次数:0 
[求助]内排序的死循环~!~!~!~

怎么我这个程序是死循环,请高手指教啊。
void createheap(int *heap,int root ,int index)
{
int i,j;
int temp;
int finish;
j=2*root;
temp=heap[root] ;
finish=0;
while(j<=index&&finish==0)
{ if(j<index)
if(heap[j]<heap[j+1])
j++;
if(temp>=heap[j])
finish=1;
else
{ heap[j/2]=heap[j] ;
j=2*j; }
}
heap[j/2]=temp;
}

void heapsort(int *heap ,int index)
{
int i ,j ,temp;
for(i=(index/2);i>=1;i--)
{ createheap(heap,i,index); }
for(i=index-1;i>=1;i--)
{ temp=heap[i+1];
heap[i+1]=heap[1];
heap[1]=temp;
createheap(heap,1,i);
printf("###sorting process:") ;
for(i=1;i<index;i++)
{ printf("%d\t",heap[i]);}
printf("\n");
}
}
void main()
{ int list[50];
int node;
int i,index;
printf("please input the values you want to sort (when end please input 0):\n");
list[0]=0;
index=1;
scanf("%d",&node);
while(node!=0||index>50)
{ list[index]=node;
index++;
scanf("%d",&node);
}
index--;
printf("scorce values:");
for(i=1;i<=index;i++)
printf("%d",list[i]);
printf("\n\n\n");
heapsort(list,index);
printf("\n sort result is:\t");
for(i=1;i<=index;i++)
printf("%d",list[i]);
printf("\n");
}


搜索更多相关主题的帖子: void 
2005-11-28 18:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-35607-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042660 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved