Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

2 modifications in the function partition of quicksort with choosing …#22

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
XxZhang2017 wants to merge1 commit intojsquared21:master
base:master
Choose a base branch
Loading
fromXxZhang2017:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modifiedExercise_23/Exercise_23_04/Exercise_23_04.class
View file
Open in desktop
Binary file not shown.
12 changes: 9 additions & 3 deletionsExercise_23/Exercise_23_04/Exercise_23_04.java
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,9 +20,15 @@ public static void quickSort(int[] list, int first, int last) {
public static int partition(int[] list, int first, int last) {
int middle = list[(list.length - 1) / 2];
// choose the median element as the pivot
int pivot = median(first, middle, last);
// here should parse the element in the list instead of
// index;
int pivot = median(list[first], middle, list[last]);
int low = first + 1; // Index for forward search
int high = last; // Index for backward search
// here should not forward the index
// the pivot is choose from median()
// instead of the first element in
// the list
int high = last; // Index for backward search

while (high > low) {
// Search forward from left
Expand DownExpand Up@@ -69,4 +75,4 @@ public static int median(int first, int middle, int last) {
return Math.max(Math.min(first, middle),
Math.min(Math.max(first, middle), last));
}
}
}

[8]ページ先頭

©2009-2025 Movatter.jp