-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgorithms.java
More file actions
41 lines (34 loc) · 1.14 KB
/
Algorithms.java
File metadata and controls
41 lines (34 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package data.visualizer;
import java.util.Arrays;
import javax.swing.*;
public class Algorithms {
public static void bubbleSort(LinkedList list, ChartPanel chart) {
int[] array = list.toArray();
int n = array.length;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (array[j] > array[j + 1]) {
// Swap
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
// Update Visualization
chart.updateData(array);
try {
Thread.sleep(500); // Delay for visualization
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
}
// Linear Search Example (Placeholder)
public static int linearSearch(int[] data, int target) {
for (int i = 0; i < data.length; i++) {
if (data[i] == target) return i;
}
return -1;
}
}