#include<stdio.h>
#define MAXN 30
void siftdown(a,i,n)
int a[];
int i,n;
{
int j,t;
t=a[i];
while((j=2*i+1)<n)
{
if(j<n-1&&a[j]<a[j+1])j++;
if(t<a[j])
{
a[i]=a[j];
i=j;
}
else break;
}
a[i]=t;
}
void heap_sort(a,n)
int a[];
int n;
{
int i,t;
for(i=(n-2)/2;i>=0;i--)
siftdown(a,i,n);
for(i=n-1;i>0;i--)
{
t=a[0];
a[0]=a[i];
a[i]=t;
siftdown(a,0,i);
}
}
void main()
{
int b[MAXN];
int n,i;
printf("Please input the No. of the node:n=");
scanf("%d",&n);
printf("Please input the array:");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
heap_sort(b,n);
for(i=0;i<n;i++)
printf("%-5d",b[i]);
printf("\n");
}
没有合适的资源?快使用搜索试试~ 我知道了~
Pra.rar_PRA 存放_PRA算法实现_习堆
共7个文件
dsp:1个
ncb:1个
opt:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 2 浏览量
2022-09-22
17:16:18
上传
评论
收藏 8KB RAR 举报
温馨提示
练习堆排序算法,将存放于数组中的一系列数通过堆将其排好序。
资源详情
资源评论
资源推荐
收起资源包目录
Pra.rar (7个子文件)
Pra7(堆排序)
Pra7.plg 242B
Pra7.c 693B
Pra7.dsw 533B
Pra7.opt 53KB
Pra7.dsp 3KB
Pra7.ncb 41KB
www.pudn.com.txt 218B
共 7 条
- 1
刘良运
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0