#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& )
};
Let’s say I have this as my header file. In my implementation for this, what is the best way to do Heap() constructor and ~Heap() destructor.
I have
Heap::Heap()
{
elements = 0;
}
Heap::~Heap()
{
array = NULL;
}
I am wondering if this is the proper way to destruct and construct an array in this case.
arrayis not dynamically allocated, so the storage for it goes away when the object no longer exists in scope. In fact, you can’t reassign toarray; it’s an error to do so.