-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectSort.java
More file actions
43 lines (35 loc) · 731 Bytes
/
Copy pathselectSort.java
File metadata and controls
43 lines (35 loc) · 731 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
42
43
/*
* Brett Waugh
* 3 December 2019
* selectSort.java
* The logic and display function for Selection Sort.
*/
public class selectSort {
/*
* Logic for Selection Sort.
*/
public static void sort(int[] data, int max) {
int min, temp;
for (int i = 0; i < max - 1; i++) {
min = i;
for (int j = i + 1; j < max; j++) {
if (data[j] < data[min]) {
min = j;
}
}
// Swap the new minimum with the first element.
temp = data[min];
data[min] = data[i];
data[i] = temp;
}
}
/*
* Display function for Selection Sort.
*/
public static void display(int[] data, int max) {
for (int i = 0; i < max; ++i) {
System.out.print(data[i] + ", ");
}
System.out.println("\n");
}
}