22
22
23
23
/**
24
24
* The array that can be sorted
25
- *
26
- * @author mhops
27
25
*/
28
26
public class SortArray extends JPanel {
29
27
public static final int DEFAULT_WIN_WIDTH = 1280 ;
@@ -45,11 +43,8 @@ public class SortArray extends JPanel {
45
43
private ISortAlgorithm algorithm ;
46
44
private long algorithmDelay = 0 ;
47
45
48
- // private final MidiSoundPlayer player;
49
46
private final JSpinner spinner ;
50
- // private final boolean playSounds;
51
47
52
- private int arrayChanges = 0 ; // Number of changes to the array the current algorithm has taken so far
53
48
54
49
public SortArray () {
55
50
setBackground (Color .DARK_GRAY );
@@ -59,8 +54,6 @@ public SortArray() {
59
54
array [i ] = i ;
60
55
barColours [i ] = 0 ;
61
56
}
62
- // player = new MidiSoundPlayer(NUM_BARS);
63
- // this.playSounds = playSounds;
64
57
spinner = new JSpinner (new SpinnerNumberModel (1 , 1 , 1000 , 1 ));
65
58
spinner .addChangeListener ((event ) -> {
66
59
algorithmDelay = (Integer ) spinner .getValue ();
@@ -92,11 +85,6 @@ private void finaliseUpdate(int value, long millisecondDelay, boolean isStep) {
92
85
} catch (InterruptedException ex ) {
93
86
Thread .currentThread ().interrupt ();
94
87
}
95
- // if (playSounds) {
96
- // player.makeSound(value);
97
- // }
98
- if (isStep )
99
- arrayChanges ++;
100
88
}
101
89
102
90
public void swap (int firstIndex , int secondIndex , long millisecondDelay , boolean isStep ) {
@@ -120,13 +108,11 @@ public void updateSingle(int index, int value, long millisecondDelay, boolean is
120
108
}
121
109
122
110
public void shuffle () {
123
- arrayChanges = 0 ;
124
111
Random rng = new Random ();
125
112
for (int i = 0 ; i < arraySize (); i ++) {
126
113
int swapWithIndex = rng .nextInt (arraySize () - 1 );
127
114
swap (i , swapWithIndex , 5 , false );
128
115
}
129
- arrayChanges = 0 ;
130
116
}
131
117
132
118
public void highlightArray () {
@@ -167,7 +153,6 @@ public void paintComponent(Graphics g) {
167
153
panelGraphics .drawString (" Current algorithm: " + algorithmName , 10 , 30 );
168
154
panelGraphics .drawString (" Time Complexity & Space Complexity: " + tandComplexity , 10 , 55 );
169
155
panelGraphics .drawString ("Current step delay: " + algorithmDelay + "ms" , 10 , 80 );
170
- // panelGraphics.drawString(" Array Changes: " + arrayChanges, 10, 105);
171
156
172
157
drawBars (panelGraphics );
173
158
} finally {
@@ -261,4 +246,4 @@ public void setAlgorithm(ISortAlgorithm algorithm) {
261
246
algorithmDelay = algorithm .getDelay ();
262
247
spinner .setValue ((int ) algorithm .getDelay ());
263
248
}
264
- }
249
+ }
0 commit comments