-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.java
More file actions
57 lines (45 loc) · 1.48 KB
/
SelectionSort.java
File metadata and controls
57 lines (45 loc) · 1.48 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package selectionsort;
/**
*
* @author lucas.monteiro
*/
public class SelectionSort {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int quantidade = 10000;
int[] vetor = new int[quantidade];
for (int i = 0; i < vetor.length; i++) {
vetor[i] = (int) (Math.random() * quantidade);
/*
* Impressão dos números gerados Aleatóriamente
System.out.print(vetor[i]+"\n");
*/
}
long tempoInicial = System.currentTimeMillis();
selectionSort(vetor);
long tempoFinal = System.currentTimeMillis();
System.out.println("Executado em = " + (tempoFinal - tempoInicial) + " ms");
}
public static void selectionSort(int[] array) {
for (int fixo = 0; fixo < array.length - 1; fixo++) {
int menor = fixo;
for (int i = menor + 1; i < array.length; i++) {
if (array[i] < array[menor]) {
menor = i;
}
}
if (menor != fixo) {
int t = array[fixo];
array[fixo] = array[menor];
array[menor] = t;
}
}
/* Impressão da visualização
* Caso deseje imprimir a ordeção irá implicar no desempenho de sua execução
for(int x=0; x<vetor.length;x++){
System.out.print(vetor[x]+"\n");
}*/
}
}