Skip to content

Commit 7a70b06

Browse files
committed
version 3.5
1 parent ca71239 commit 7a70b06

24 files changed

+666
-594
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ To build a runnable jar, simply run Apache Ant inside the 'dist' directory!
2525
- Toggle Timo Bingmann's "end sweep" animation
2626
- Refactored / optimized code
2727

28+
## 6/8/2020 - Version 3.5
29+
_changelog coming soon_
30+
2831
## 6/4/2020 - Version 3.2
2932
- New sort: Optimized Cocktail Shaker Sort
3033
- Significant refactoring for MultipleSortThreads and RunAllSorts

dist/arrayVisualizer.jar

1.93 KB
Binary file not shown.

src/main/ArrayVisualizer.java

Lines changed: 136 additions & 101 deletions
Large diffs are not rendered by default.

src/prompts/ViewPrompt.java

Lines changed: 91 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
import main.ArrayVisualizer;
1111
import templates.Frame;
1212
import visuals.VisualStyles;
13+
import javax.swing.JButton;
14+
import javax.swing.GroupLayout.Alignment;
15+
import javax.swing.GroupLayout;
16+
import javax.swing.LayoutStyle.ComponentPlacement;
1317

1418
/*
1519
*
@@ -81,6 +85,8 @@ private void initComponents() {
8185
this.spiralDots= new javax.swing.JButton();
8286
this.rainbow = new javax.swing.JButton();
8387
this.hoops = new javax.swing.JButton();
88+
this.sineWave = new javax.swing.JButton();
89+
this.waveDots = new javax.swing.JButton();
8490

8591
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
8692
setResizable(false);
@@ -166,58 +172,77 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
166172
spiralDotsActionPerformed(evt);
167173
}
168174
});
169-
175+
176+
sineWave.setText("Sine Wave");
177+
sineWave.addActionListener(new java.awt.event.ActionListener() {
178+
@Override
179+
public void actionPerformed(java.awt.event.ActionEvent evt) {
180+
sineWaveActionPerformed(evt);
181+
}
182+
});
183+
waveDots.setText("Wave Dots");
184+
waveDots.addActionListener(new java.awt.event.ActionListener() {
185+
@Override
186+
public void actionPerformed(java.awt.event.ActionEvent evt) {
187+
waveDotsActionPerformed(evt);
188+
}
189+
});
190+
170191
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
171-
getContentPane().setLayout(layout);
172192
layout.setHorizontalGroup(
173-
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER, true)
174-
.addGroup(layout.createSequentialGroup()
175-
.addGap(18, 18, 18)
176-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, true)
177-
.addComponent(this.barGraph, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
178-
.addComponent(this.rainbow, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
179-
.addComponent(this.colorCircle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
180-
.addComponent(this.disparity, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
181-
.addComponent(this.disparityDots, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
182-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
183-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, true)
184-
.addComponent(this.dotGraph, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
185-
.addComponent(this.triangleMesh, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
186-
.addComponent(this.spiral, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
187-
.addComponent(this.hoops, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
188-
.addComponent(this.spiralDots, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
189-
.addGap(18, 18, 18))
190-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER, true)
191-
.addComponent(this.jLabel1))
192-
);
193+
layout.createParallelGroup(Alignment.CENTER)
194+
.addComponent(jLabel1)
195+
.addGroup(Alignment.LEADING, layout.createSequentialGroup()
196+
.addGap(18)
197+
.addGroup(layout.createParallelGroup(Alignment.LEADING)
198+
.addComponent(barGraph, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
199+
.addComponent(rainbow, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
200+
.addComponent(colorCircle, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
201+
.addComponent(disparity, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
202+
.addComponent(disparityDots, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE)
203+
.addComponent(sineWave, GroupLayout.DEFAULT_SIZE, 105, Short.MAX_VALUE))
204+
.addPreferredGap(ComponentPlacement.RELATED)
205+
.addGroup(layout.createParallelGroup(Alignment.LEADING)
206+
.addComponent(waveDots, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
207+
.addComponent(dotGraph, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
208+
.addComponent(triangleMesh, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
209+
.addComponent(spiral, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
210+
.addComponent(hoops, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE)
211+
.addComponent(spiralDots, GroupLayout.DEFAULT_SIZE, 101, Short.MAX_VALUE))
212+
.addGap(18))
213+
);
193214
layout.setVerticalGroup(
194-
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER, true)
215+
layout.createParallelGroup(Alignment.CENTER)
195216
.addGroup(layout.createSequentialGroup()
196-
.addGap(7, 7, 7)
197-
.addComponent(this.jLabel1)
198-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
199-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, true)
200-
.addComponent(this.barGraph, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
201-
.addComponent(this.dotGraph, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
202-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
203-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, true)
204-
.addComponent(this.rainbow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
205-
.addComponent(this.triangleMesh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
206-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
207-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, true)
208-
.addComponent(this.colorCircle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
209-
.addComponent(this.hoops, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
210-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
211-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, true)
212-
.addComponent(this.disparity, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
213-
.addComponent(this.spiral, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
214-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
215-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, true)
216-
.addComponent(this.disparityDots, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
217-
.addComponent(this.spiralDots, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
218-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
219-
.addContainerGap(18, Short.MAX_VALUE))
220-
);
217+
.addGap(7)
218+
.addComponent(jLabel1)
219+
.addPreferredGap(ComponentPlacement.UNRELATED)
220+
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
221+
.addComponent(barGraph)
222+
.addComponent(dotGraph))
223+
.addPreferredGap(ComponentPlacement.UNRELATED)
224+
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
225+
.addComponent(rainbow)
226+
.addComponent(triangleMesh))
227+
.addPreferredGap(ComponentPlacement.UNRELATED)
228+
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
229+
.addComponent(colorCircle)
230+
.addComponent(hoops))
231+
.addPreferredGap(ComponentPlacement.UNRELATED)
232+
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
233+
.addComponent(disparity)
234+
.addComponent(spiral))
235+
.addPreferredGap(ComponentPlacement.UNRELATED)
236+
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
237+
.addComponent(disparityDots)
238+
.addComponent(spiralDots))
239+
.addPreferredGap(ComponentPlacement.UNRELATED)
240+
.addGroup(layout.createParallelGroup(Alignment.LEADING)
241+
.addComponent(sineWave)
242+
.addComponent(waveDots))
243+
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
244+
);
245+
getContentPane().setLayout(layout);
221246

222247
pack();
223248
}// </editor-fold>//GEN-END:initComponents
@@ -228,6 +253,7 @@ private void setAllFieldsFalse(){
228253
ArrayVisualizer.togglePixels(false);
229254
ArrayVisualizer.toggleRainbow(false);
230255
ArrayVisualizer.toggleSpiral(false);
256+
ArrayVisualizer.toggleWave(false);
231257
}
232258

233259
private void barGraphActionPerformed(java.awt.event.ActionEvent evt) {
@@ -306,6 +332,21 @@ private void spiralDotsActionPerformed(java.awt.event.ActionEvent evt) {
306332
UtilFrame.jButton2ResetText();
307333
dispose();
308334
}
335+
private void sineWaveActionPerformed(java.awt.event.ActionEvent evt) {
336+
setAllFieldsFalse();
337+
ArrayVisualizer.setVisual(VisualStyles.BARS);
338+
ArrayVisualizer.toggleWave(true);
339+
UtilFrame.jButton2ResetText();
340+
dispose();
341+
}
342+
private void waveDotsActionPerformed(java.awt.event.ActionEvent evt) {
343+
setAllFieldsFalse();
344+
ArrayVisualizer.setVisual(VisualStyles.PIXELS);
345+
ArrayVisualizer.togglePixels(true);
346+
ArrayVisualizer.toggleWave(true);
347+
UtilFrame.jButton2ResetText();
348+
dispose();
349+
}
309350

310351
// Variables declaration - do not modify//GEN-BEGIN:variables
311352
private javax.swing.JButton barGraph;
@@ -318,7 +359,7 @@ private void spiralDotsActionPerformed(java.awt.event.ActionEvent evt) {
318359
private javax.swing.JButton disparityDots;
319360
private javax.swing.JButton rainbow;
320361
private javax.swing.JButton hoops;
362+
private javax.swing.JButton sineWave;
363+
private javax.swing.JButton waveDots;
321364
private javax.swing.JLabel jLabel1;
322-
// End of variables declaration//GEN-END:variables
323-
324365
}

src/sorts/BogoBogoSort.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package sorts;
2+
3+
import templates.BogoSorting;
4+
5+
public final class BogoBogoSort extends BogoSorting {
6+
public BogoBogoSort(utils.Delays delayOps, utils.Highlights markOps, utils.Reads readOps, utils.Writes writeOps) {
7+
super(delayOps, markOps, readOps, writeOps);
8+
9+
this.setSortPromptID("Bogobogo");
10+
this.setRunAllID("Bogobogo Sort");
11+
this.setReportSortID("Bogobogosort");
12+
this.setCategory("Distributive Sorts");
13+
this.isComparisonBased(false); //Comparisons are not used to swap elements
14+
this.isBucketSort(false);
15+
this.isRadixSort(false);
16+
this.isUnreasonablySlow(true);
17+
this.setUnreasonableLimit(8);
18+
this.isBogoSort(true);
19+
}
20+
21+
@Override
22+
public void runSort(int[] array, int currentLength, int bucketCount) {
23+
int bogoLength = 2;
24+
boolean arrayNotSorted = true;
25+
26+
while(arrayNotSorted) {
27+
if(bogoIsSorted(array, bogoLength)) {
28+
if(bogoLength == currentLength) {
29+
arrayNotSorted = false;
30+
}
31+
else {
32+
bogoLength++;
33+
}
34+
}
35+
else {
36+
bogoLength = 2;
37+
}
38+
if(arrayNotSorted) bogoSwap(array, bogoLength, 0);
39+
}
40+
}
41+
}

src/templates/BogoSorting.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ protected BogoSorting(Delays delayOps, Highlights markOps, Reads readOps, Writes
3737
}
3838

3939
private static int randomPosition(int length, int offset) {
40-
return (int) ((Math.random() * (length - offset)) + offset);
40+
return (int) (Math.random() * (length - offset));
4141
}
4242

4343
protected void bogoSwap(int[] array, int length, int offset){
4444
for(int i = offset; i < length; i++) {
45-
Writes.swap(array, i, BogoSorting.randomPosition(length, offset), 0, true, false);
45+
Writes.swap(array, i, BogoSorting.randomPosition(length, i) + i, 0, true, false);
4646
}
4747
}
4848

src/templates/MultipleSortThread.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,14 @@ protected synchronized void runIndividualSort(Sort sort, int bucketCount, int[]
5959

6060
protected abstract void executeSortList(int[] array) throws Exception;
6161
protected abstract void runThread(int[] array, int current, int total, boolean runAllActive) throws Exception;
62-
public abstract void reportCategorySorts(int[] array) throws Exception;
63-
public abstract void reportAllSorts(int[] array, int current, int total) throws Exception;
62+
63+
public synchronized void reportCategorySorts(int[] array) throws Exception {
64+
this.runThread(array, 0, 0, false);
65+
}
66+
67+
public synchronized void reportAllSorts(int[] array, int current, int total) throws Exception {
68+
this.runThread(array, current, total, true);
69+
}
6470

6571
public int getSortCount() {
6672
return this.sortCount;

0 commit comments

Comments
 (0)