Skip to content

Add Sorting algorithm QuickSortMedianOfThree - #294

Closed
italo-batista wants to merge 1 commit into
TheAlgorithms:masterfrom
italo-batista:QuickSortMedianOfThree
Closed

italo-batista wants to merge 1 commit into
TheAlgorithms:masterfrom
italo-batista:QuickSortMedianOfThree

Conversation

@italo-batista

Copy link
Copy Markdown

No description provided.

@italo-batista italo-batista mentioned this pull request Oct 31, 2017

@christianbender christianbender left a comment

Copy link
Copy Markdown

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;

Copy link
Copy Markdown

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;

Copy link
Copy Markdown

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)

Copy link
Copy Markdown

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();

Copy link
Copy Markdown

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.

}

}

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants