#include <cstdlib>
#include <iostream>
using namespace std;
const unsigned long MAX_SIZE = 20;
typedef int ItemType;
class Heap {
private:
ItemType array[MAX_SIZE];
int elements; //how many elements are in the heap
public:
Heap( )
~Heap( )
bool IsEmpty( ) const
bool IsFull( ) const
Itemtype Retrieve( )
void Insert( const Itemtype& )
};
Run Code Online (Sandbox Code Playgroud)
假设我将此作为我的头文件.在我的实现中,做Heap()构造函数和~Heap()析构函数的最佳方法是什么.
我有
Heap::Heap()
{
elements = 0;
}
Heap::~Heap()
{
array = NULL;
}
Run Code Online (Sandbox Code Playgroud)
我想知道这是否是在这种情况下破坏和构造数组的正确方法.