怎么我这个程序是死循环,请高手指教啊。
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");
}