| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 568 人关注过本帖
标题:[求助]内排序的死循环~!~!~!~
只看楼主 加入收藏
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
快速回复:[求助]内排序的死循环~!~!~!~
数据加载中...
 
   



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

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