forked from marktennyson/Java-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSorter.java
More file actions
36 lines (35 loc) · 894 Bytes
/
Copy pathSelectionSorter.java
File metadata and controls
36 lines (35 loc) · 894 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
class SSorter{
int[] Arr;
int arrLen;
SSorter(int[] Arr){
this.Arr = Arr;
this.arrLen = this.Arr.length;
}
void sort(){
for (int i=0; i<this.arrLen; i++){
int _idx = i;
for (int j=i+1; j<this.arrLen; j++){
if (this.Arr[_idx] > this.Arr[j]){
_idx = j;
}
}
int temp1 = this.Arr[_idx];
int temp2 = this.Arr[i];
this.Arr[i] = temp1;
this.Arr[_idx] = temp2;
}
}
void display(){
for (int k = 0; k < this.arrLen; k++) {
System.out.println(this.Arr[k]);
}
}
}
public class SelectionSorter {
public static void main(String[] args) {
int[] arr = {12,3,54,15,76};
SSorter sorter = new SSorter(arr);
sorter.sort();
sorter.display();
}
}