堆排序 HeapSort
来源:互联网 发布:mac壁纸存放路径 编辑:程序博客网 时间:2024/06/03 21:37
堆排序
#include<iostream>using namespace std;void HeapAdjust(int H[],int s,int m){int rc=H[s];for(int j=2*s;j<=m;j*=2){if(j<m&&H[j]<H[j+1])j++;if(rc>H[j])break;H[s]=H[j];s=j;}H[s]=rc;}void HeapSort(int H[],int H_length){for(int i=H_length/2;i>0;i--)HeapAdjust(H,i,H_length); for(int i=H_length,temp;i>1;--i){temp=H[1];H[1]=H[i];H[i]=temp;HeapAdjust(H,1,i-1);}}int main(){int H[100]={0},n,i=1;int H_length=0;cout<<"请输入需要排序的数,并以0作为结束"<<endl;while(cin>>n) {if(n==0)break;H[i]=n;i++;}H_length=i-1;HeapSort(H,H_length);for(i=1;i<=H_length;i++){cout<<H[i]<<" "; }}
0 0
- 堆排序(HeapSort)
- 堆排序 heapSort
- HeapSort 堆排序
- C++ 堆排序 (HeapSort)
- 堆排序heapsort
- 堆排序(HeapSort)
- HeapSort(堆排序 C++)
- 堆排序(Heapsort)
- 堆排序 (Heapsort)
- 堆排序 Heapsort
- 堆排序(heapsort)
- 堆排序(HeapSort)
- 堆排序(heapsort)
- 堆排序(heapsort)
- heapsort堆排序
- 堆排序heapsort
- 堆排序 HeapSort
- 堆排序(Heapsort)
- altium designer 重新给文件命名
- iOS中一个tableView中显示两种cell的问题
- 关于跳槽与工资的事
- 图片加载库Glide用法
- java 虚拟机访问对象的两种机制到底有什区别 http://www.cnblogs.com/h2-database/archive/2012/06/27/2572498.html
- 堆排序 HeapSort
- 线性布局 LinearLayout
- java - 锁
- Hibernate
- Android_ListView_有Header或Footer时onItemClick里的position的问题
- Linux下搭建maven 私服
- 计算机专业英语 学习笔记 1
- EditText
- 遇到IOError: CRC check failed这样的问题的可能解决方法