heapsort.cpp

来自「数据结构与算法分析」· C++ 代码 · 共 24 行

CPP
24
字号
#include <iostream.h>
#include <stdlib.h>
#include <string.h>

#include "book.h"
#include "compare.h"

#include "maxheap.h"

template <class Elem, class Comp>
void heapsort(Elem A[], int n) { // Heapsort
  Elem mval;
  maxheap<Elem,Comp> H(A, n, n); // Build the heap
  for (int i=0; i<n; i++)        // Now sort
    H.removemax(mval); // Removemax places max at end
}

template <class Elem, class Comp>
void sort(Elem* array, int n) {
 heapsort<Elem,Comp>(array, n);
}

#include "sortmain.cpp"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?