Skip to content

Commit 5206647

Browse files
committed
Fix Bubble Sort Java visualization
1 parent 894df28 commit 5206647

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Brute Force/Bubble Sort/Code.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import org.algorithm_visualizer.ChartTracer;
2-
import org.algorithm_visualizer.LogTracer;
3-
import org.algorithm_visualizer.Randomize;
1+
import org.algorithm_visualizer.*;
42

53
import java.util.Arrays;
64

@@ -17,18 +15,20 @@ public static void main(String[] args) {
1715
int length = array.length;
1816

1917
logTracer.printf("original array = %s\n",Arrays.toString(array));
20-
21-
chartTracer.set(array).delay();
18+
chartTracer.set(array);
19+
Layout.setRoot(new VerticalLayout(new Commander[]{chartTracer, logTracer}));
20+
Tracer.delay();
2221

2322
boolean flag;
2423

2524
for (int i = length - 1; i > 0; i--) {
2625
flag = true;
2726
for (int j = 0; j < i; j++) {
28-
chartTracer.select(j).delay();
29-
chartTracer.select(j + 1).delay();
27+
chartTracer.select(j);
28+
chartTracer.select(j + 1);
29+
Tracer.delay();
3030
if (array[j] > array[j + 1]) {
31-
logTracer.printf("swap %s and %s \n",array[j],array[j + 1]);
31+
logTracer.printf("swap %s and %s\n",array[j],array[j + 1]);
3232
swap(j, j + 1, array);
3333
flag = false;
3434
}
@@ -41,16 +41,19 @@ public static void main(String[] args) {
4141
}
4242

4343

44-
logTracer.printf("\n sorted array = %s",Arrays.toString(array));
44+
logTracer.printf("sorted array = %s\n",Arrays.toString(array));
4545

4646
}
4747

4848
private static void swap(int x, int y, Integer [] array) {
4949
int temp = array[x];
5050
array[x] = array[y];
5151
array[y] = temp;
52-
chartTracer.patch(x, array[x]).patch(y, array[y]).delay();
53-
chartTracer.depatch(x).depatch(y);
52+
chartTracer.patch(x, array[x]);
53+
chartTracer.patch(y, array[y]);
54+
Tracer.delay();
55+
chartTracer.depatch(x);
56+
chartTracer.depatch(y);
5457
}
5558

5659
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy