forked from AllAlgorithms/java
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.java
More file actions
Latest commit
29 lines (26 loc) · 745 Bytes
/
Copy pathSelectionSort.java
File metadata and controls
29 lines (26 loc) · 745 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
/**
* Java implementation of merge sort
*
* @author Dimitris Glynatsis
* @email dim.glynatsis@gmail.com
*/
publicclassSelectionSort {
staticvoidselection(int[] a, intleft, intright) {
for (inti = left; i < right; i++) {
intmin = i;
for (intj = i + 1; j <= right; j++)
if (a[j] < a[min])
min = j;
inttemp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
publicstaticvoidmain(String[] args) {
int[] a = { 5, 4, 6, 1, 3, 8 };
SelectionSorts = newSelectionSort();
s.selection(a, 0, a.length - 1);
for (inti = 0; i < a.length; i++)
System.out.println(a[i]);
}
}