HeapSort
来源:互联网 发布:森田玻尿酸乳液知乎 编辑:程序博客网 时间:2024/06/14 01:57
#include <iostream>using namespace std;//find the maxnmal numbera and put it to the place 0 void FindMaxInHeap(int a[],int size){for(int i = size -1;i > 0;i--){int parent = i / 2;int child = i;//if(i < size-1 && a[i] < a[i+1]){//cout<<"CHILD"<<child<<endl;//child++;//}if(a[child] > a[parent]){swap(a[child],a[parent]);}}}//for each root, find the max number...void HeapSort(int a[],int size){for(int i = size ;i > 0;i--){FindMaxInHeap(a,i);swap(a[0],a[i-1]);}}int main(){int n;while(cin>>n && n!=0){int a[1001];for(int i=0;i<n;i++){cin>>a[i];}HeapSort(a,n);for(int i=0;i<n-1;i++){cout<<a[i]<<' ';}cout<<a[n-1]<<endl;}}
0 0
- Heapsort
- Heapsort
- HeapSort
- heapsort
- HeapSort
- HeapSort
- HeapSort
- heapsort
- heapsort
- heapsort
- HeapSort
- Heapsort
- HeapSort
- heapSort
- HeapSort
- heapSort
- HeapSort
- heapsort
- 漫谈程序员系列:别说“我已经很努力了”
- echo -e -n
- Java虚拟机_内存管理_垃圾收集GC
- 《黑客与画家书评》
- 黑马程序员——数组
- HeapSort
- 面试总结
- 基于python的豆瓣“我看过的电影”的爬虫
- hdoj 1116 Play on Words 【并查集】+【欧拉路】
- JSON(二)
- Open the Java build path property page of project 'Speaker'
- 博客已迁移~~
- 关于导出函数与调用约定,C++ Builder 调用 VC++ 编译的DLL
- Anagram Search -- CodeForces