Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
41 lines (37 loc) · 998 Bytes

File metadata and controls

41 lines (37 loc) · 998 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
// Java program for implementation of Selection Sort
class SelectionSort
{
void sorting(ArrayList<Integer> arr)
{
int n = arr.size();
for (int i = 0; i < n-1; i++)
{
int min_idx = i;
for (int j = i+1; j < n; j++)
if (arr.get(j) < arr.get(min_idx))
min_idx = j;
int temp = arr.get(min_idx);
arr.set(min_idx, arr.get(i));
arr.set(i,temp);
}
}
public static void main(String args[]) throws IOException
{
SelectionSort obj = new SelectionSort();
String pathToFile = "./Sorting/unsorted.txt";
File unsorted = new File(pathToFile);
Scanner sc = new Scanner(unsorted);
sc.useDelimiter(",");
ArrayList<Integer> arr = new ArrayList<Integer>();
while(sc.hasNext()){
arr.add(sc.nextInt());
}
obj.sorting(arr);
System.out.println("Sorted array");
System.out.println( arr);
sc.close();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.