#include <iostream.h>
#include<stdlib.h>
const int num=10001;
void Heapadjust( int heap[], int index, int sum)
{
int heapval=heap[index];
for( int j=2*index; j<=sum ; j*=2 )
{
if( j<sum && heap[j]<heap[j+1] )
++j;
if( heapval>=heap[j] )
break;
heap[index]=heap[j];
index=j;
}
heap[index]=heapval;
}
void Heapsort(int heap[],int sum)
{
for( int i=sum/2; i>0 ; --i )
{
Heapadjust( heap, i, sum );
}
for( i=sum; i>1 ; --i )
{
int temp=heap[1];
heap[1]=heap[i];
heap[i]=temp;
Heapadjust( heap, 1, i-1 );
}
}
void main()
{
int heap[num];
for( int j=1; j<num ; j++)
{
heap[j]=rand();
}
Heapsort( heap, num-1);
for(int k=1; k<num ; k++ )
{
cout<<"NO."<<k<<"---"<<heap[k]<<endl;
}
}
排序算法之堆排序算法:用C++语言实现堆排序算法
需积分: 1 34 浏览量
2024-05-22
20:12:53
上传
评论
收藏 5KB RAR 举报
![avatar](https://profile-avatar.csdnimg.cn/436d7efc72e54325aab8a84a9c64992d_xiongyajun123.jpg!1)
天`南
- 粉丝: 1286
- 资源: 264
最新资源
- 基于LUT查找表方法的正弦信号产生器FPGA实现,包含testbench,包括程序,注释,操作步骤
- Screenshot_20240618_174113.jpg
- matlab画正余弦函数图的代码!!!!!
- 2_期末网店运营报告模版.pdf
- MyBatisCodeHelperPro 3.3.2-2322 2023.2-2024.1
- 基于Python的简单的学生成绩管理程序设计(课程设计)
- jdk-8u20-windows-x64安装版本-jdk-8u301-linux-x64解压版
- 植物大战僵尸杂交版 修改阳光和冷却
- html css js网页设计ntion-model-for-开发笔记
- 数据库课程设计-processing开发笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)