cs325/hw2/mergesort3time.cpp
//This is the recursive function that splits the current array into thirds using indexes and math
This is the recursive function that splits the current array into thirds using indexes and math
This is the recursive function that splits the current array into thirds using indexes and math
void mergeSort3(int origArray[], int lowerBound, int upperBound, int sortedArray[]) {
	if (upperBound - lowerBound < 2) {
		return;
  	}
	int firstThird = lowerBound + ((upperBound - lowerBound) / 3);
	int secondThird = lowerBound + 2 * ((upperBound - lowerBound) / 3) + 1;
	mergeSort3(sortedArray, lowerBound, firstThird, origArray);
	mergeSort3(sortedArray, firstThird, secondThird, origArray);
	mergeSort3(sortedArray, secondThird, upperBound, origArray);
	merge(sortedArray, lowerBound, firstThird, secondThird, upperBound, origArray);
}
void mergeSort3 ( int origArray [ ] , int lowerBound , int upperBound , int sortedArray [ ] ) { if ( upperBound - lowerBound < 2 ) { return ; } int firstThird = lowerBound + ( ( upperBound - lowerBound ) / 3 ) ; int secondThird = lowerBound + 2 * ( ( upperBound - lowerBound ) / 3 ) + 1 ; mergeSort3 ( sortedArray , lowerBound , firstThird , origArray ) ; mergeSort3 ( sortedArray , firstThird , secondThird , origArray ) ; mergeSort3 ( sortedArray , secondThird , upperBound , origArray ) ; merge ( sortedArray , lowerBound , firstThird , secondThird , upperBound , origArray ) ; }
This is the recursive function that splits the current array into thirds using indexes and math
This is the recursive function that splits the current array into thirds using indexes and math
//If the array is size 1, return //This is where the array is split into thirds, the indexes are calculated instead of actually splitting the array //Call mergeSort3 recursively, this will sort each third of the array //First third is lowerBound - firstThird //Second third is firstThird - secondThird //Third third is secondThird - upperBound //This will merge all parts of the array