hsort.h
来自「data structures, algorithms and Applicat」· C头文件 代码 · 共 27 行
H
27 行
// file hsort.h
//heap sort
#ifndef HeapSort_
#define HeapSort_
#include "maxheap.h"
template <class T>
void HeapSort(T a[], int n)
{// Sort a[1:n] using the heap sort method.
// create a max heap of the elements
MaxHeap<T> H(1);
H.Initialize(a,n,n);
// extract one by one from the max heap
T x;
for (int i = n-1; i >= 1; i--) {
H.DeleteMax(x);
a[i+1] = x;
}
// save array a from heap destructor
H.Deactivate();
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?