Skip to content

Commit 1211fed

Browse files
committed
Large Update
Improved Audio/Visuals More sorts More view styles (missing linked normal dots atm) Many optimizations
1 parent 02d9c59 commit 1211fed

File tree

11 files changed

+282
-86
lines changed

11 files changed

+282
-86
lines changed

dist/Array_Visualizer.jar

4.69 KB
Binary file not shown.

src/ArrayVisualizer.java

Lines changed: 86 additions & 47 deletions
Large diffs are not rendered by default.

src/HeapSort.java

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package array.visualizer;
2+
3+
import static array.visualizer.ArrayVisualizer.*;
4+
import static array.visualizer.Swaps.*;
5+
6+
public class HeapSort {
7+
8+
static int SLP = 1;
9+
10+
static int heapify(int parent, int child1, boolean max){
11+
aa+=2;
12+
comps+=1;
13+
if((max && array[child1]>array[parent]) || (!max && array[child1]<array[parent])){
14+
swap(array, parent, child1, SLP);
15+
return child1;
16+
}
17+
18+
return -1;
19+
}
20+
21+
static int heapify(int parent, int child1, int child2, boolean max){
22+
int candidate = 0;
23+
24+
aa+=4;
25+
comps+=2;
26+
27+
if(max){
28+
if(array[child1]>array[child2])
29+
candidate = child1;
30+
else
31+
candidate = child2;
32+
33+
if(array[candidate]>array[parent]){
34+
swap(array, parent, candidate, SLP);
35+
return candidate;
36+
}
37+
}
38+
else{
39+
if(array[child1]<array[child2])
40+
candidate = child1;
41+
else
42+
candidate = child2;
43+
44+
if(array[candidate]<array[parent]){
45+
swap(array, parent, candidate, SLP);
46+
return candidate;
47+
}
48+
}
49+
50+
return -1;
51+
}
52+
53+
static void maxheapify(int len) {
54+
for(int i = len/2-1; i >= 0; i--){
55+
int child2 = i*2+2;
56+
if(child2>=len)
57+
//Special case for only one child.
58+
heapify(i, child2-1, true);
59+
else
60+
heapify(i,child2-1,child2,true);
61+
}
62+
}
63+
64+
// static void maxheapify(int len){
65+
// int loc = 0;
66+
// int child1 = 1;
67+
// int child2 = 2;
68+
//
69+
// while(loc != -1){
70+
// child1 = loc*2+1;
71+
// child2 = child1+1;
72+
//
73+
//
74+
//
75+
// if(child1>=len)
76+
// //DONE
77+
// return;
78+
//
79+
// System.out.println("loc: "+loc+" child1: "+child1+" child2: "+child2);
80+
// System.out.println("loc: "+array[loc]+" child1: "+array[child1]+" child2: "+array[child2]);
81+
// if(child2>=len)
82+
// //SPECIAL SINGLE CHILD CASE
83+
// loc = heapify(loc, child1, true);
84+
// else
85+
// loc = heapify(loc, child1, child2, true);
86+
//
87+
// System.out.println("Chose "+loc);
88+
// }
89+
// }
90+
91+
static void maxheapsort(){
92+
//maxheapifyinitial(array.length);
93+
//swap(array, 0, array.length-1, SLP);
94+
for(int i = array.length; i > 1; i--){
95+
maxheapify(i);
96+
swap(array, 0, i-1, SLP);
97+
}
98+
}
99+
100+
static void minheapsort(){
101+
}
102+
}

src/InsertionSort.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void insertionSort() {
1616
int pos;
1717
for(int i = 1; i < array.length; i++){
1818
pos = i;
19-
marked.set(0, i);
19+
//marked.set(0, i);
2020
while(pos>0&&array[pos]<=array[pos-1]){
2121
comps+=2;
2222
swap(array, pos, pos-1,Math.max(pos%50-48,0));
@@ -29,7 +29,7 @@ public static void insertionSort(int start, int end, double slpamt) {
2929
int pos;
3030
for(int i = start; i < end; i++){
3131
pos = i;
32-
marked.set(0, i);
32+
//marked.set(0, i);
3333
while(pos>start&&array[pos]<=array[pos-1]){
3434
comps+=2;
3535
swap(array, pos, pos-1);

src/RadixLSDInPlace.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void inPlaceRadixLSDSort(int radix)throws Exception{
2121
} else {
2222
for(int j = 0; j<vregs.length;j++)
2323
marked.set(j+1,vregs[j]);
24-
swapUpTo(pos,vregs[digit-1]);
24+
swapUpToNM(pos,vregs[digit-1]);
2525
for(int j = digit-1; j > 0; j--)
2626
vregs[j-1]--;
2727
}

src/Swaps.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,22 @@ public static void swapnm(int[] a, int i, int j, int pause) {
3939
}
4040

4141
public static void swapUpTo(int pos, int to){
42+
if(to - pos > 0)
43+
for(int i = pos; i < to; i++)
44+
swap(array, i, i+1, i%240/239);
45+
else
46+
for(int i = pos; i > to; i--)
47+
swap(array, i, i-1, i%240/239);
48+
}
49+
50+
public static void swapUpToNM(int pos, int to){
4251
if(to - pos > 0)
4352
for(int i = pos; i < to; i++)
4453
swapnm(array, i, i+1, i%240/239);
4554
else
4655
for(int i = pos; i > to; i--)
4756
swapnm(array, i, i-1, i%240/239);
48-
}
57+
}
4958

5059
public static void swapUp(int pos) {
5160
for(int i = pos; i < array.length; i++)

src/TimeSort.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
import static array.visualizer.ArrayVisualizer.*;
9-
import static array.visualizer.BubbleSort.*;
9+
import static array.visualizer.InsertionSort.*;
1010
import java.util.ArrayList;
1111
import java.util.logging.Level;
1212
import java.util.logging.Logger;
@@ -36,8 +36,8 @@ public void run() {
3636
}
3737
for(Thread t : threads)
3838
t.start();
39-
sleep(array.length * A);
40-
bubbleSort();
39+
Thread.sleep(array.length * A);
40+
insertionSort(0,array.length,0.2d);
4141

4242
}
4343
static volatile int next = 0;

src/Transcriptions.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,32 +82,7 @@ public static void transcribe(ArrayList<Integer>[] registers, int [] array, int
8282
registers[ai].clear();
8383
}
8484
}
85-
86-
public static void inPlaceRadixLSDSort(int radix)throws Exception{
87-
int pos = 0;
88-
int[] vregs = new int[radix-1];
89-
int maxpower = analyze(radix);
90-
for(int p = 0; p <= maxpower; p++){
91-
for(int i = 0; i < vregs.length; i++)
92-
vregs[i]=array.length-1;
93-
pos = 0;
94-
for(int i = 0; i < array.length; i++){
95-
int digit = getDigit(array[pos], p, radix);
96-
if(digit==0) {
97-
pos++;
98-
marked.set(0, pos);
99-
} else {
100-
for(int j = 0; j<vregs.length;j++)
101-
marked.set(j+1,vregs[j]);
102-
swapUpTo(pos,vregs[digit-1]);
103-
for(int j = digit-1; j > 0; j--)
104-
vregs[j-1]--;
105-
}
106-
}
107-
108-
}
109-
}
110-
85+
11186
public static void fancyTranscribe(ArrayList<Integer>[] registers) throws Exception {
11287
int[] tmp = new int[array.length];
11388
boolean[] tmpwrite = new boolean[array.length];

src/ViewPrompt.form

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
<Component id="jButton2" max="32767" attributes="0"/>
3131
<Component id="jButton1" alignment="1" max="32767" attributes="0"/>
3232
<Component id="jButton3" alignment="1" max="32767" attributes="0"/>
33+
<Component id="jButton7" alignment="0" max="32767" attributes="0"/>
3334
</Group>
3435
<EmptySpace max="32767" attributes="0"/>
3536
<Group type="103" groupAlignment="0" max="-2" attributes="0">
3637
<Component id="jButton4" alignment="0" max="32767" attributes="0"/>
3738
<Component id="jButton5" alignment="0" max="32767" attributes="0"/>
3839
<Component id="jButton6" alignment="0" max="32767" attributes="0"/>
40+
<Component id="jButton8" alignment="0" max="32767" attributes="0"/>
3941
</Group>
4042
<EmptySpace min="-2" pref="24" max="-2" attributes="0"/>
4143
</Group>
@@ -66,7 +68,12 @@
6668
<Component id="jButton6" min="-2" max="-2" attributes="0"/>
6769
<Component id="jButton3" alignment="0" min="-2" max="-2" attributes="0"/>
6870
</Group>
69-
<EmptySpace max="32767" attributes="0"/>
71+
<EmptySpace type="unrelated" max="-2" attributes="0"/>
72+
<Group type="103" groupAlignment="3" attributes="0">
73+
<Component id="jButton7" alignment="3" min="-2" max="-2" attributes="0"/>
74+
<Component id="jButton8" alignment="3" min="-2" max="-2" attributes="0"/>
75+
</Group>
76+
<EmptySpace pref="16" max="32767" attributes="0"/>
7077
</Group>
7178
</Group>
7279
</DimensionLayout>
@@ -131,5 +138,21 @@
131138
<Property name="text" type="java.lang.String" value="Select View Type"/>
132139
</Properties>
133140
</Component>
141+
<Component class="javax.swing.JButton" name="jButton7">
142+
<Properties>
143+
<Property name="text" type="java.lang.String" value="D. Circle"/>
144+
</Properties>
145+
<Events>
146+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton7ActionPerformed"/>
147+
</Events>
148+
</Component>
149+
<Component class="javax.swing.JButton" name="jButton8">
150+
<Properties>
151+
<Property name="text" type="java.lang.String" value="D. C. Dots"/>
152+
</Properties>
153+
<Events>
154+
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton8ActionPerformed"/>
155+
</Events>
156+
</Component>
134157
</SubComponents>
135158
</Form>

src/ViewPrompt.java

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ private void initComponents() {
4646
jButton5 = new javax.swing.JButton();
4747
jButton6 = new javax.swing.JButton();
4848
jLabel1 = new javax.swing.JLabel();
49+
jButton7 = new javax.swing.JButton();
50+
jButton8 = new javax.swing.JButton();
4951

5052
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
5153
setResizable(false);
@@ -96,6 +98,20 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
9698

9799
jLabel1.setText("Select View Type");
98100

101+
jButton7.setText("D. Circle");
102+
jButton7.addActionListener(new java.awt.event.ActionListener() {
103+
public void actionPerformed(java.awt.event.ActionEvent evt) {
104+
jButton7ActionPerformed(evt);
105+
}
106+
});
107+
108+
jButton8.setText("D. C. Dots");
109+
jButton8.addActionListener(new java.awt.event.ActionListener() {
110+
public void actionPerformed(java.awt.event.ActionEvent evt) {
111+
jButton8ActionPerformed(evt);
112+
}
113+
});
114+
99115
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
100116
getContentPane().setLayout(layout);
101117
layout.setHorizontalGroup(
@@ -105,12 +121,14 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
105121
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
106122
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
107123
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
108-
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
124+
.addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
125+
.addComponent(jButton7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
109126
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
110127
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
111128
.addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
112129
.addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
113-
.addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
130+
.addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
131+
.addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
114132
.addGap(24, 24, 24))
115133
.addGroup(layout.createSequentialGroup()
116134
.addGap(65, 65, 65)
@@ -134,7 +152,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
134152
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
135153
.addComponent(jButton6)
136154
.addComponent(jButton3))
137-
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
155+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
156+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
157+
.addComponent(jButton7)
158+
.addComponent(jButton8))
159+
.addContainerGap(16, Short.MAX_VALUE))
138160
);
139161

140162
pack();
@@ -145,6 +167,7 @@ private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
145167
CIRCLEDRAW = false;
146168
COLORONLY = false;
147169
PIXELDRAW = false;
170+
DISPARITYDRAW = false;
148171
dispose();
149172
}//GEN-LAST:event_jButton1ActionPerformed
150173

@@ -153,6 +176,7 @@ private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
153176
CIRCLEDRAW = true;
154177
COLORONLY = true;
155178
PIXELDRAW = false;
179+
DISPARITYDRAW = false;
156180
dispose();
157181
}//GEN-LAST:event_jButton2ActionPerformed
158182

@@ -161,6 +185,7 @@ private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
161185
CIRCLEDRAW = true;
162186
COLORONLY = false;
163187
PIXELDRAW = false;
188+
DISPARITYDRAW = false;
164189
dispose();
165190
}//GEN-LAST:event_jButton3ActionPerformed
166191

@@ -169,6 +194,7 @@ private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
169194
CIRCLEDRAW = false;
170195
COLORONLY = true;
171196
PIXELDRAW = false;
197+
DISPARITYDRAW = false;
172198
dispose();
173199
}//GEN-LAST:event_jButton4ActionPerformed
174200

@@ -177,6 +203,7 @@ private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
177203
CIRCLEDRAW = false;
178204
COLORONLY = false;
179205
PIXELDRAW = true;
206+
DISPARITYDRAW = false;
180207
dispose();
181208
}//GEN-LAST:event_jButton5ActionPerformed
182209

@@ -185,16 +212,37 @@ private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
185212
CIRCLEDRAW = true;
186213
COLORONLY = false;
187214
PIXELDRAW = true;
215+
DISPARITYDRAW = false;
188216
dispose();
189217
}//GEN-LAST:event_jButton6ActionPerformed
190218

219+
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
220+
// TODO add your handling code here:
221+
CIRCLEDRAW = true;
222+
COLORONLY = false;
223+
PIXELDRAW = false;
224+
DISPARITYDRAW = true;
225+
dispose();
226+
}//GEN-LAST:event_jButton7ActionPerformed
227+
228+
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
229+
// TODO add your handling code here:
230+
CIRCLEDRAW = true;
231+
COLORONLY = false;
232+
PIXELDRAW = true;
233+
DISPARITYDRAW = true;
234+
dispose();
235+
}//GEN-LAST:event_jButton8ActionPerformed
236+
191237
// Variables declaration - do not modify//GEN-BEGIN:variables
192238
private javax.swing.JButton jButton1;
193239
private javax.swing.JButton jButton2;
194240
private javax.swing.JButton jButton3;
195241
private javax.swing.JButton jButton4;
196242
private javax.swing.JButton jButton5;
197243
private javax.swing.JButton jButton6;
244+
private javax.swing.JButton jButton7;
245+
private javax.swing.JButton jButton8;
198246
private javax.swing.JLabel jLabel1;
199247
// End of variables declaration//GEN-END:variables
200248
}

0 commit comments

Comments
 (0)