Question: My code is not compiling and I am not sure what is going on theres only so much code I can change. Here is the

My code is not compiling and I am not sure what is going on theres only so much code I can change. Here is the sorting algorithm template
void HeapKMerge::runSort(unsigned int firstIndex, unsigned int lastIndex){
if (firstIndex >= lastIndex){
// Base case: If the array has 0 or 1 item, no more sorting is needed.
return;
}
// Calculate the number of items in the current array region
unsigned int numItems = lastIndex - firstIndex +1;
// Calculate the size of each subarray
unsigned int subarraySize = numItems / K;
// Create an array to store the last indexes of subarrays
unsigned int lastIndexesArray[K];
// Compute the last indexes of each subarray
for (unsigned int i =0; i < K; i++){
if (i < K -1){
lastIndexesArray[i]= firstIndex +(i +1)* subarraySize -1;
} else {
lastIndexesArray[i]= lastIndex;
}
}
// Recursively sort each subarray
for (unsigned int i =0; i < K; i++){
runSort(firstIndex + i * subarraySize, lastIndexesArray[i]);
}
// Create a temporary array to store the current region
T* arrayCopy = new T[numItems];
// Copy the current region into the temporary array
for (unsigned int i = firstIndex; i <= lastIndex; i++){
arrayCopy[i - firstIndex]= this->arr[i];
}
// Adjust the constructor call to use the corrected type for lastIndexes
MinHeap minHeap(arrayCopy, numItems, static_cast(firstIndex), lastIndexesArrayInt);
// Iterate and sort one element at a time
for (unsigned int i = firstIndex; i <= lastIndex; i++){
this->arr[i]= minHeap.getSmallest();
}
// Clean up the temporary array
delete[] arrayCopy;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!