Skip to content

Commit

Permalink
Add MANY shuffles to the button (including Recursively Reversed)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Dec 3, 2020
1 parent c291178 commit b3c3635
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 31 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ To build a runnable jar, simply run Apache Ant inside the 'dist' directory!
- Organize list of sorts into more categories
- Run All Sorts in specific category
- Subheadings for customizable sorts (e.g. display the number of buckets during a bucket sort)
- "Many Similar" distribution ((i/5) * 5, as an example)
- "Pipe organ" distribution (half ascending, half descending)
- Fixed circular pointer with much cleaner math
- Toogle between pointer and black bar with circular visuals
Expand Down
12 changes: 9 additions & 3 deletions src/main/ArrayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import utils.Delays;
import utils.Highlights;
import utils.Shuffles;
import utils.Statistics;
import utils.Writes;

/*
Expand Down Expand Up @@ -35,7 +36,12 @@ of this software and associated documentation files (the "Software"), to deal
final public class ArrayManager {
private int[] presortedArray;
private utils.Shuffles[] shuffleTypes;
private String[] shuffleIDs = {"Randomly", "Shuffled Odds", "Backwards", "Few Unique", "Almost Sorted", "Already Sorted"};
private String[] shuffleIDs = { "Randomly", "Shuffled Odds", "Backwards", "Recursively Reversed",
"Few Unique", "Almost Sorted", "Decreasing Random", "Logarithmic Slopes", "Triangular",
"Scrambled Head", "Scrambled Tail", "Half Reversed", "Perlin Noise", "Perlin Noise Curve",
"Heapified", "Interlaced", "Poplar Heapified", "Binary Search Tree", "Reversed Sawtooth",
"Reversed Final Merge", "Double Layered", "Final Pairwise Pass", "Bell Curve", "Sawtooth",
"Final Reversed Merge", "Final Bitonic Pass", "Pipe Organ", "Final Radix Pass", "Already Sorted" };

private volatile boolean MUTABLE;

Expand Down Expand Up @@ -113,14 +119,14 @@ public void setShuffle(Shuffles choice) {
}

public void shuffleArray(int[] array, int currentLen, ArrayVisualizer ArrayVisualizer) {
if(Shuffles != Shuffles.ALREADY) this.initializeArray(array);
this.initializeArray(array);

String tmp = ArrayVisualizer.getHeading();
ArrayVisualizer.setHeading("Shuffling...");

double speed = Delays.getSleepRatio();

if(ArrayVisualizer.getSortingThread() != null && ArrayVisualizer.getSortingThread().isAlive()) {
if(ArrayVisualizer.isActive()) {
double sleepRatio;

//TODO: Replace with continuous function
Expand Down
9 changes: 8 additions & 1 deletion src/main/ArrayVisualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,10 @@ public void setShadowArray() {
}
}

public boolean isSorted() {
return this.statSnapshot.findSegments(this.array, this.sortLength)[0] == 1;
}

public int[] getArray() {
return this.array;
}
Expand Down Expand Up @@ -470,8 +474,11 @@ public void setPower(int newPower) {
this.power = newPower;
}

public int getLogBaseNOfLength(int base) {
return (int) (Math.log(this.sortLength) / Math.log(base));
}
public int getLogBaseTwoOfLength() {
return (int) (Math.log(this.sortLength) / Math.log(2));
return getLogBaseNOfLength(2);
}

public boolean shuffleEnabled() {
Expand Down
34 changes: 8 additions & 26 deletions src/prompts/ShufflePrompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addGroup(layout.createSequentialGroup()
.addGap(5, 5, 5)
.addGap(20, 20, 20)
.addComponent(this.jLabel1)
.addGap(5, 5, 5))
.addGroup(layout.createSequentialGroup()
.addComponent(this.jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(this.jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(20, 20, 20)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
Expand All @@ -134,8 +135,8 @@ public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
.addComponent(this.jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, true)
.addComponent(this.jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(5, 5, 5))
.addComponent(this.jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(20, 20, 20))
);

pack();
Expand All @@ -144,28 +145,9 @@ public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) throws Exception {//GEN-FIRST:event_jList1ValueChanged
// TODO add your handling code here:
int selection = jList1.getSelectedIndex();
switch (selection) {
case 0:
ArrayManager.setShuffle(ArrayManager.getShuffles()[0]);
break;
case 1:
ArrayManager.setShuffle(ArrayManager.getShuffles()[1]);
break;
case 2:
ArrayManager.setShuffle(ArrayManager.getShuffles()[2]);
break;
case 3:
ArrayManager.setShuffle(ArrayManager.getShuffles()[3]);
break;
case 4:
ArrayManager.setShuffle(ArrayManager.getShuffles()[4]);
break;
case 5:
ArrayManager.setShuffle(ArrayManager.getShuffles()[5]);
break;
default:
break;
}
Shuffles[] shuffles = ArrayManager.getShuffles();
if (selection >= 0 && selection < shuffles.length)
ArrayManager.setShuffle(shuffles[selection]);
UtilFrame.jButton6ResetText();
dispose();
}//GEN-LAST:event_jList1ValueChanged
Expand Down

0 comments on commit b3c3635

Please sign in to comment.