-
Notifications
You must be signed in to change notification settings - Fork 0
/
EmployeeSort.java
40 lines (30 loc) · 804 Bytes
/
EmployeeSort.java
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
public class EmployeeSort {
public Employee[] selectionSort(Employee[] employeeList) {
int min;
Employee temp;
for (int x = 0; x < employeeList.length - 1; x++) {
min = x;
for (int y = x + 1; y < employeeList.length; y++) {
if (employeeList[y].compareTo(employeeList[min]) < 0) {
min = y;
}
}
temp = employeeList[min];
employeeList[min] = employeeList[x];
employeeList[x] = temp;
}
return employeeList;
}
public Employee[] insertionSort(Employee[] employeeList) {
for (int x = 1; x < employeeList.length; x++) {
Employee key = employeeList[x];
int pos = x;
while (pos > 0 && employeeList[pos-1].compareTo(key) > 0) {
employeeList[pos] = employeeList[pos-1];
pos--;
}
employeeList[pos] = key;
}
return employeeList;
}
}