-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathSelectionSort10
More file actions
41 lines (39 loc) · 921 Bytes
/
SelectionSort10
File metadata and controls
41 lines (39 loc) · 921 Bytes
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.*;
public class SelectionSort10 {
public static void selsort(int A[]) {
int i, j, small, tmp, pos;
for (i = 0; i < 10; i++) {
small = A[i];
pos = i;
for (j = i + 1; j < 10; j++) {
if (A[j] < small) {
small = A[j];
pos = j;
}
}
tmp = A[i];
A[i] = A[pos];
A[pos] = tmp;
}
System.out.println("Array in ascending order=");
for (i = 0; i < 10; i++)
System.out.println(A[i]);
}
public static void main(String[] args) {
int A[] = new int[10];
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String inStr = null;
System.out.println("Enter 10 elements of array=");
try {
for (int i = 0; i < 10; i++) {
inStr = buf.readLine();
A[i] = Integer.parseInt(inStr);
}
} catch (Exception e) {
System.out.println("Error in data entry");
System.out.println("Exception=" + e);
return;
}
selsort(A);
}
}