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

Commit 6bb19e6

Browse files
committed
AbstractSortArray, SortArray: Moved compareAndSwap() from abstract class to interface (Java SE 8+).
1 parent c18cd33 commit 6bb19e6

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

‎src/io/nayuki/sortalgodemo/core/AbstractSortArray.java‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ public void swap(int i, int j) {
7676
}
7777

7878

79-
public boolean compareAndSwap(int i, int j) {
80-
if (compare(i, j) > 0) {
81-
swap(i, j);
82-
return true;
83-
} else
84-
return false;
85-
}
86-
87-
8879
/* Sorting progress visualization */
8980

9081
// Does nothing by default; can be overridden.

‎src/io/nayuki/sortalgodemo/core/SortArray.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ public interface SortArray {
8080
* @return whether initially array[i] > array[j], which causes them to be swapped
8181
* @throws IndexOutOfBoundsException if not (0 ≤ {@code i}, {@code j} < {@code length()})
8282
*/
83-
public boolean compareAndSwap(int i, int j);
83+
public default boolean compareAndSwap(int i, int j) {
84+
if (compare(i, j) > 0) {
85+
swap(i, j);
86+
return true;
87+
} else
88+
return false;
89+
}
8490

8591

8692
/**

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /