-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseleccion.java
More file actions
28 lines (28 loc) · 1.04 KB
/
Copy pathseleccion.java
File metadata and controls
28 lines (28 loc) · 1.04 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
public static void seleccion(float A[], String[] nom) {
int i, j, pos;
float menor, tmp;
String menornom, tmpnom;
for (i = 0; i < A.length - 1; i++) { // tomamos como menor el primero
menor = A[i]; // de los elementos que quedan por ordenar
menornom = nom[i];
pos = i; // y guardamos su posición
for (j = i + 1; j < A.length; j++) { // buscamos en el resto
if (A[j] < menor) { // del array algún elemento
menor = A[j]; // menor que el actual
menornom = nom[j];
pos = j;
}
}
if (pos != i) { // si hay alguno menor se intercambia
tmp = A[i];
tmpnom = nom[i];
A[i] = A[pos];
nom[i] = nom[pos];
A[pos] = tmp;
nom[pos] = tmpnom;
}
}
for (i = 1; i < A.length; i++) {
System.out.println(nom[i] + "----" + A[i] + "\n");
}
}