Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



ποΈ Extend Mergesort by additional variant
ποΈ General
The process of the 3-way Mergesort is the same as the "normal" mergesort. The idea ist just to split the array into one more part and by this increase it's efficiency.
π‘π¬π Implementation
Initially the implementation seemed easy. Just to the same as the first time implementing the algorithm and extend it by the handling of an addtional array. So of i went:
π οΈ Refactoring
First of all the class needed to be refactored to allow multiple variants of the sorting algorithm. This was done with the same principal as the other algorithms, by extending the
sortmethod by an additional parameter that allows to call different variants dynamic. The initial implementation was moved into a new methodvariant1and was set as the default of the parameter.π© Implementation
Now the fun part begun and a new method was added for the new implementation named
variant2. And initially the methods looks really similar. We devide the provided array and call the method recursivly with the seperated array and use a check of the length agains<=0as termination condition.π€² Merge
The merging on the other hand now has to be extended. Before we just had to check the two values provided. Now there are three that need to be checked which requires a few more conditions.
Addtionally we now have three conditions that have to be met while looping over the different arrays and have to concatinate the rest with additional logic instead of just appending the remaining elements to the results array.
Adjusting
Since the code kept growing i decided to more or less scrap the current state and make it dynamic. This approach would, when done correctly reduce the code needed further.
Changing the signature
The first thing that needed to be adjusted is the methods definition. Instead of providing three arrays, the parameter was switched to a single array that contains the arrays and therefore is iterable.