Feat/my mergesort#5
Open
Bunsarak27 wants to merge 5 commits into
Open
Conversation
Includes a partially-authored README file. However, there are still some changes to make, as there are sections which we cannot fill out yet. This commit was accidentally authored under my university GitHub identity, woops. --------- Co-authored-by: Izak Baldacchino <a1830164@student.adelaide.edu.au>
Includes the implementation for the merge function. The makefile has been revamped in order to allow a unit test executable to built and run to test the function. --------- Co-authored-by: Izak Baldacchino <a1830164@student.adelaide.edu.au>
Includes a gitignore file which uses the basic C/C++ template from GitHub. Also includes `compile_flags.txt` in the ignore path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Implement a serial my_mergesort(left, right) that will act as the base case for our upcoming parallel_mergesort. This PR does not change threading yet.
What I changed
Added a recursive my_mergesort(int left, int right):
Base case: if (left >= right) return; (0 or 1 element ⇒ already sorted).
Compute mid = left + (right - left)/2 (overflow-safe pattern).
Recurse on [left..mid] and [mid+1..right].
Call merge(left, mid, mid+1, right) to combine the two sorted halves.
Inline comments explaining:
Why the base case uses >=.
Why we split with (right - left)/2.
The invariant that merge() expects inclusive ranges and a split at mid | mid+1.