Skip to content

Commit b7d6ad4

Browse files
Sorting Visualizer.java
1 parent 685ba20 commit b7d6ad4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Sorting Visualizer.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
public class BubbleSortVisualizer {
2+
public static void main(String[] args) throws Exception {
3+
int[] a = {5, 1, 4, 2, 8};
4+
5+
for (int i = 0; i < a.length - 1; i++) {
6+
for (int j = 0; j < a.length - i - 1; j++) {
7+
if (a[j] > a[j+1]) {
8+
int t = a[j];
9+
a[j] = a[j+1];
10+
a[j+1] = t;
11+
}
12+
13+
for (int x : a) System.out.print(x + " ");
14+
System.out.println();
15+
Thread.sleep(500);
16+
}
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)