Skip to content

Commit

Permalink
Create RunQuickSorts.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Apr 6, 2021
1 parent c0f87e9 commit 2ad3081
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/threads/RunQuickSorts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package threads;

import main.ArrayVisualizer;
import panes.JErrorPane;
import sorts.quick.*;
import sorts.templates.Sort;
import utils.Shuffles;

/*
*
MIT License
Copyright (c) 2021 ArrayV 4.0 Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*
*/

final public class RunQuickSorts extends MultipleSortThread {
private Sort CubeRootQuickSort;

public RunQuickSorts(ArrayVisualizer arrayVisualizer) {
super(arrayVisualizer);
this.sortCount = 1;
this.categoryCount = this.sortCount;

CubeRootQuickSort = new CubeRootQuickSort(this.arrayVisualizer);
}

@Override
protected synchronized void executeSortList(int[] array) throws Exception {
RunQuickSorts.this.runIndividualSort(CubeRootQuickSort, 0, array, 2048, 1, false);
}

@Override
protected synchronized void runThread(int[] array, int current, int total, boolean runAllActive) throws Exception {
if(arrayVisualizer.isActive())
return;

Sounds.toggleSound(true);
arrayVisualizer.setSortingThread(new Thread() {
@Override
public void run() {
try{
if(runAllActive) {
RunQuickSorts.this.sortNumber = current;
RunQuickSorts.this.sortCount = total;
}
else {
RunQuickSorts.this.sortNumber = 1;
}

arrayManager.toggleMutableLength(false);

arrayVisualizer.setCategory("Exchange Sorts");

RunQuickSorts.this.executeSortList(array);

if(!runAllActive) {
arrayVisualizer.setCategory("Run Exchange Sorts");
arrayVisualizer.setHeading("Done");
}

arrayManager.toggleMutableLength(true);
}
catch (Exception e) {
JErrorPane.invokeErrorMessage(e);
}
Sounds.toggleSound(false);
arrayVisualizer.setSortingThread(null);
}
});
arrayVisualizer.runSortingThread();
}
}

0 comments on commit 2ad3081

Please sign in to comment.