Question: import java.io.*; import java.util.Scanner; public class SortingAlgorithm{ public static void bubbleSort(int arr[]){ int n = arr.length; for (int i = 0; i < n-1; i++)

import java.io.*; import java.util.Scanner;

public class SortingAlgorithm{

public static void bubbleSort(int arr[]){

int n = arr.length;

for (int i = 0; i < n-1; i++)

for (int j = 0; j < n-i-1; j++)

if (arr[j] > arr[j+1]){

int temp = arr[j];

arr[j] = arr[j+1];

arr[j+1] = temp;

}

}

public static void selectionsort(int arr[]){

int n = arr.length;

for (int i = 0; i < n-1; i++){

int min_idx = i;

for (int j = i+1; j < n; j++)

if (arr[j] < arr[min_idx])

min_idx = j;

int temp = arr[min_idx];

arr[min_idx] = arr[i];

arr[i] = temp;

}

}

public static void insertionsort(int arr[]){

int n = arr.length;

for (int i=1; i

int key = arr[i];

int j = i-1;

while (j>=0 && arr[j] > key){

arr[j+1] = arr[j];

j = j-1;

}

arr[j+1] = key;

}

}

public void printArray(int arr[]){

int n = arr.length;

for (int i=0; i

System.out.print(arr[i] + " ");

System.out.println();

}

public static void main(String [] args) throws FileNotFoundException{ Scanner input=new Scanner(new File(args [0]));

while(input.hasNextLine()) System.out.println(input.nextLine()); input.close();

SortingAlgorithm ob1 = new SortingAlgorithm();

SortingAlgorithm ob2 = new SortingAlgorithm();

SortingAlgorithm ob3 = new SortingAlgorithm();

ob1.bubbleSort(arr);

ob2.selectionsort(arr);

ob3.insertionsort(arr);

System.out.println("Sorted array after bubble sort");

ob1.printArray(arr);

System.out.println("Sorted array after selection sort");

ob2.printArray(arr);

System.out.println("Sorted array after insertion sort");

ob3.printArray(arr);

}

}

data1.data

2 10 2 20 198 116 99 48 202 121 105 95 114 96 158 127 184 155 146 78 165 196

I need to be abe to read the data files, but i cant figure out how to read it or format it. How do i read the data files? Thank you.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!