Ok the red lines cause faults when they are not commented out.
Can anybody fix this?
Code:
//copy constructor
heap::heap(const heap &aHeap)
{
delete [] heapArr;
heapArr = NULL;
cout << heapArr <<endl;
heapArr = new HeapNode[aHeap.maxSize];
if (heapArr != NULL)
{
maxSize = aHeap.maxSize;
curSize = aHeap.curSize;
for (int a = 0; a <= curSize; a++)
{
heapArr[a] = aHeap.heapArr[a];
}
}
else
maxSize = 0;
}
bool heap::buildHeap(HeapNode *n, const int nodes)
{
//delete previous heap if one exists
if(curSize != 0)
{
delete [] heapArr;
heapArr = NULL;
curSize = 0;
maxSize = 0;
}
cout << "reallocate" <<endl;
cout << heapArr <<endl;
heapArr = new HeapNode[nodes];
cout << "after reallocate " <<endl;
if (heapArr != NULL)
{
maxSize = nodes;
for (int a = 1; a <= maxSize; a++)
{
cout << "begin copy" <<endl;
heapArr[a] = n[a];
curSize = a;
percDown(a);
}
return true;
}
else
maxSize = 0;
return false;
}