Dúvidas sobre Bubble Sort & SelectionSort
Olá pessoal, tudo de boa?
Estou iniciando meus estudos em Java, comecei a estudar ordenação e tenho uma pequena dúvida,
Eu fiz esse programa aqui para entender como funciona o BubbleSort, porem esta ordenando de forma crescente, como eu poderia fazer parar ordenar de forma decrescente ?
package BubbleSort;
public class BubbleSort {
public static void main(String args[]){
int [] v = {5, 2, 4, 3, 0, 9, 7, 8, 1,6};
BubbleSort bs = new BubbleSort();
bs.ordenar(v);
for (int num :v){
System.out.println(num+"");
}
}
public void ordenar(int[] v){
for(int i=0; i < v.length -1; i++){
for (int j=0; j < v.length -1; j++){
if(v[j] > v[j+1]){
int aux = v[j];
v[j] = v[j+1];
v[j+1] = aux;
}
}
}
}
}
Estou iniciando meus estudos em Java, comecei a estudar ordenação e tenho uma pequena dúvida,
Eu fiz esse programa aqui para entender como funciona o BubbleSort, porem esta ordenando de forma crescente, como eu poderia fazer parar ordenar de forma decrescente ?
package BubbleSort;
public class BubbleSort {
public static void main(String args[]){
int [] v = {5, 2, 4, 3, 0, 9, 7, 8, 1,6};
BubbleSort bs = new BubbleSort();
bs.ordenar(v);
for (int num :v){
System.out.println(num+"");
}
}
public void ordenar(int[] v){
for(int i=0; i < v.length -1; i++){
for (int j=0; j < v.length -1; j++){
if(v[j] > v[j+1]){
int aux = v[j];
v[j] = v[j+1];
v[j+1] = aux;
}
}
}
}
}
Lucas
Curtidas 0