Commit bc7608b1 authored by edmundszagars's avatar edmundszagars
Browse files

Adding "BubbleSort" class

parent 9671cc23
import sorting_algorithms.BubbleSort;
import java.io.FileNotFoundException;
import java.util.Arrays;
......@@ -5,7 +7,12 @@ public class Main {
public static void main(String[] args) throws FileNotFoundException {
GetDataFromCSV get = new GetDataFromCSV();
get.setnFileLocation("data2.csv");
for (int i = 0 ; i < get.getDataFromCSV().size();i++)
System.out.println(get.getDataFromCSV().get(i).size());
Object[] arrray = get.getDataFromCSV().get(1).toArray();
double[] data =new double[arrray.length];
for (int i = 0; i < arrray.length;i++){
data[i] = (double) arrray[i];
}
System.out.println(Arrays.toString(BubbleSort.bubbleSort(data)));
}
}
package sorting_algorithms;
public class BubbleSort {
public static double[] bubbleSort(double[] array) {
int n = array.length;
int k;
for (int m = n; m >= 0; m--) {
for (int i = 0; i < n - 1; i++) {
k = i + 1;
if (array[i] > array[k]) {
swapNumbers(i, k, array);
}
}
}
return array;
}
private static void swapNumbers(int i, int k, double[] array) {
double tmp;
tmp = array[i];
array[i] = array[k];
array[k] = tmp;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment