能不能帮忙看一下我编的这个堆排序
用的是VS2012,一运行就死循环了,不知道是什么问题。#include <iostream>
void heapadjust(int a[],int i,int length)
{
for(int child=2*i+1;i<=length/2-1;i=child)
{
if(a[child]>a[child+1]&&child<length-1)
child=child+1;
if(a[child]>a[i])
{
int temp;
temp=a[i];
a[i]=a[child];
a[child]=temp;
}
}
}
void buildheap(int a[],int length)
{
int i=length/2-1;
for (;i>0;i--)
{
heapadjust(a,i,length);
}
}
void heapsort(int a[],int length)
{
int temp;
int i=length;
for(i=length;i>0;i--)
{
buildheap(a,i);
temp=a[0];
a[0]=a[i];
a[i]=temp;
}
}
void main()
{
int a[]={10,15,56,25,30,70,12,3,92,32};
std::cout<<"original array= ";
for(int i=0;i<10;i++)
{
std::cout<<a[i]<<" ";
}
std::cout<<"\n";
heapsort(a,10);
std::cout<<"current array= ";
for(int i=0;i<10;i++)
{
std::cout<<a[i]<<" ";
}
std::cout<<"\n";
system ("pause");
}