maxheap.h

来自「经典c++程序的实现」· C头文件 代码 · 共 19 行

H
19
字号
class heap {                 // Max-heap class
private:
  ELEM* Heap;                // Pointer to the heap array
  int size;                  // Maximum size of the heap
  int n;                     // Number of elements now in the heap
  void siftdown(int);        // Put an element in its correct place
public:
  heap(ELEM*, int, int);     // Constructor
  int heapsize() const;      // Return current size of the heap
  bool isLeaf(int) const;    // TRUE if pos is a leaf position
  int leftchild(int) const;  // Return position for left child
  int rightchild(int) const; // Return position for right child
  int parent(int) const;     // Return position for parent of pos
  void insert(const ELEM);   // Insert value into heap
  ELEM removemax();          // Remove maximum value
  ELEM remove(int);          // Remove value at specified position
  void buildheap();          // Heapify contents of Heap
};

⌨️ 快捷键说明

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