“Bubble Sort em java” Respostas de código

Bubble classy java

public class BubbleSortExample {  
    static void bubbleSort(int[] arr) {  
        int n = arr.length;  
        int temp = 0;  
         for(int i=0; i < n; i++){  
                 for(int j=1; j < (n-i); j++){  
                          if(arr[j-1] > arr[j]){  
                                 //swap elements  
                                 temp = arr[j-1];  
                                 arr[j-1] = arr[j];  
                                 arr[j] = temp;  
                         }  
                          
                 }  
         }  
  
}  
Anxious Albatross

Bubble Sort em java

    public static void sort(int[] arr) {
        int n = arr.length;

        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {

        int[] xr = {1, 3, 5, 2, 4};
        sort(xr);
        System.out.println(Arrays.toString(xr));
    }
Chathumal Sangeeth

Código de classificação da bolha

func Sort(arr []int) []int {
	for i := 0; i < len(arr)-1; i++ {
		for j := 0; j < len(arr)-i-1; j++ {
			if arr[j] > arr[j+1] {
				temp := arr[j]
				arr[j] = arr[j+1]
				arr[j+1] = temp
			}
		}
	}
	return arr
}
Talented Tern

Bubble classy java


list.set(list.get(j+1), temp);

Frightened Fly

números inteiros de classificação de bolhas

for (int i = 0; i < n-1; i++) 
            for (int j = 0; j < n-i-1; j++) 
                if (arr[j] > arr[j+1]) 
                { 
                    // swap arr[j+1] and arr[i] 
                    int temp = arr[j]; 
                    arr[j] = arr[j+1]; 
                    arr[j+1] = temp; 
                } 
Frantic Ferret

Respostas semelhantes a “Bubble Sort em java”

Perguntas semelhantes a “Bubble Sort em java”

Mais respostas relacionadas para “Bubble Sort em java” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código