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 7de10fa

Browse files
committed
VisualSortArray, LaunchFrame: Renamed method, added state check.
1 parent 0449c96 commit 7de10fa

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

‎src/io/nayuki/sortalgodemo/visual/LaunchFrame.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ private void doSort() {
264264
String msg = String.format("%s: %d elements, %d comparisons, %d swaps",
265265
algorithm.getName(), array.length(), array.getComparisonCount(), array.getSwapCount());
266266
try {
267-
array.assertSorted();
267+
array.finishSorting();
268268
} catch (AssertionError e) {
269269
msg = algorithm.getName() + ": Sorting failed";
270270
}

‎src/io/nayuki/sortalgodemo/visual/VisualSortArray.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ public long getSwapCount() {
152152

153153

154154
// Checks if the array is sorted. Returns silently if so, throws AssertionError if not.
155-
public void assertSorted() {
155+
public void finishSorting() {
156+
if (isDone)
157+
throw new IllegalStateException();
156158
for (int i = 1; i < values.length; i++) {
157159
if (values[i - 1] > values[i])
158160
throw new AssertionError();

0 commit comments

Comments
(0)

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