I need some dire help. Whenever I execute my program I get this message "./main: free(): invalid next size (fast)". Which leads me to believe something with my dynamic allocation of an array. I've used a debugger and pinpointed the error to the method where I'm trying to increase the size of the array. I've been pouring over the code for hours and cant seem to find whats wrong. I was hoping someone could take a look and tell me whats wrong.
void buildMinHeap(int key)
{
if (len == 1) //array is already allocated one int
{
a[0] = key;
pos++;
}
else
{
int len = pos+1; //pos is the length
ItemType *temp = new ItemType[len+1]; //ItemType is int
for(int i=0; i<len; i++)
{
temp[i] = a[i];
}
delete[] a;
a = NULL;
len = length(temp);
temp[len-1] = key;
cout << len <<endl;
a = new ItemType[len];
for(int i=0; i<len-1; i++)
{
a[i] = temp[i];
}
pos++;
int first = 0;
while(first < pos)
{
heapifyMax(a, 0, first);
first++;
}
}
}