飞光数科 2017-03-15 11:55 采纳率: 33.3%
浏览 1062

C++堆排序问题,不显示结果

#include
#include
#include
using namespace std;//建立树和堆排序
int h[101];
int n;
void swape(int m,int n)
{
h[m]^=h[n];
h[n]^=h[m];
h[m]^=h[n];
}
void siftdown(int i)
{
int t=0;
int flag=0;
while(2*i<=n&&flag==0)
{
if(h[i] t=2*i;
if(2*i+1 t=2*i+1;
if(t!=i)
{
swape(t,i);
}
else
flag=1;
}
return;
}
/*void siftup(int i)
{
int t,flag=0;
t=i/2;
while(h[t] {
swap(t,i);
i=t;
t/=2;
}
}*/
void creat()
{
for(int i=n/2;i>=1;i--)
{
siftdown(i);
}
return;
}
/*
void headsort()
{
while(n>1)
{
swape(n,1);
n--;
siftdown(1);
}
return;
}*/
int deletemax()
{
int t;
t=h[1];
h[1]=h[n];
n--;
siftdown(1);
return t;
}
int main()
{
int num;
cin>>num;
for(int i=1;i<=num;i++)
cin>>h[i];
n=num;
creat();
for(int i=1;i<=num;i++)
cout<<h[i]<<" ";
}
这个程序运行不出结果,求告知原因,最好能加一下修改

  • 写回答

2条回答 默认 最新

  • 伪造的时空 2017-03-15 12:23
    关注

    void siftdown(int i) 函数不全,请把代码补全:

    if(h[i] t=2*i;
    if(2*i+1 t=2*i+1;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?