We usually learn in college that to sort entire vectors, we use a technique called bubble sort :
int[] vetorOrdenado = new int[8];
vetorOrdenado[0] = 2;
vetorOrdenado[1] = 41;
vetorOrdenado[2] = 12;
vetorOrdenado[3] = 6;
vetorOrdenado[4] = 5;
vetorOrdenado[5] = 29;
vetorOrdenado[6] = 17;
vetorOrdenado[7] = 3;
for(int i = 0; i < vetorOrdenado.length;i++){
for(int j = 0; j < vetorOrdenado.length - 1; j++){
if(vetorOrdenado[i] < vetorOrdenado[j]){
int aux = vetorOrdenado[i];
vetorOrdenado[i] = vetorOrdenado[j];
vetorOrdenado[j] = aux;
}
}
}
This technique sorts a vector of integers, as can be seen in the ideone .
Is there another way to sort numeric vectors without using a loop inside a loop, such as bubble sort ? Collections
does not have any way to sort a vector that way?