-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.java
More file actions
28 lines (21 loc) · 891 Bytes
/
SelectionSort.java
File metadata and controls
28 lines (21 loc) · 891 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
package trabalhoGrauB1;
import java.util.LinkedList;
public class SelectionSort {
public String name = "Selection Sort";
public String description = "Consiste em comparar a cada interação um elemento com outros, visando encontrar o menor. Dessa forma, podemos entender que não existe um melhor caso mesmo que o vator esteja ordenado ou em ordem inversa serão executados dois laços no algoritmo, o externo e o interno.";
void ordenarDados(LinkedList<Integer> list)
{
int n = list.size();
for (int i = 0; i < n-1; i++) {
int min_idx = i;
for (int j = i+1; j < n; j++) {
if (list.get(j) < list.get(min_idx)) {
min_idx = j;
}
}
int temp = list.get(min_idx);
list.set(min_idx, list.get(i));
list.set(i, temp);
}
}
}