-
Notifications
You must be signed in to change notification settings - Fork 20k
Add Sorting algorithm QuickSortMedianOfThree #294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Sorting algorithm QuickSortMedianOfThree #294
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Work! I have some requests
private void medianOfThree(int[] array, int leftIndex, int rightIndex){ | ||
|
||
int shortter = leftIndex; | ||
int mid = leftIndex + (rightIndex - leftIndex) / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write instead int mid = (rightIndex + leftIndex) / 2;
. Because simpler!
} | ||
|
||
private void changePivot(int[] array, int leftIndex, int rightIndex) { | ||
int pivotIndex = leftIndex + (rightIndex - leftIndex) / 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write instead int pivotIndex = (rightIndex + leftIndex) / 2;
. Because simpler.
} | ||
|
||
private void swap(int[] array, int i, int j) { | ||
if(array == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use curly braces.
- This exception handling you can write to the methods above, too.
int leftIndex = 0; | ||
int rightIdex = array.length - 1; | ||
|
||
QuickSortMedianOfThree quick = new QuickSortMedianOfThree(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you write the methods above as static
you can use the methods right on.
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put in some comments in your code.
No description provided.