-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection.java
More file actions
39 lines (28 loc) · 953 Bytes
/
Selection.java
File metadata and controls
39 lines (28 loc) · 953 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
class Selection{
static void sort(int[] a) {
for (int i = 0; i < a.length - 1; i++){
int min_idx = i;
for (int j = i+1; j < a.length; j++){
if (a[j] < a[min_idx]){
min_idx = j;
}
}
int temp_idx = a[i];
a[i] = a[min_idx];
a[min_idx] = temp_idx;
}//end of sub-array loop
}//end of void sort
void printArray(int[] a){
for (int i = 0; i < a.length; i++){
System.out.print(a[i] + " ");
}
System.out.println();
}//end of printArray
public static void main(String[] args) {
Selection obj = new Selection();
int[] a = {65,22,47,-1,19};
obj.sort(a);
System.out.println("Sorted Array is: ");
obj.printArray(a);
}
}//end of class