Advertisement
fmbalvarez

Burbujeo

Nov 14th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.69 KB | None | 0 0
  1.  
  2. public class Burbujeo {
  3.    
  4.     public void burbujeo(int [] arreglo){
  5.        
  6.         for (int i = 0; i < arreglo.length; i++){
  7.            
  8.             for (int j = 0; j < (arreglo.length - i - 1);  j++){
  9.                
  10.                 if (arreglo[j+1] < arreglo[j]){
  11.                    
  12.                     int temporal = arreglo [j];
  13.                     arreglo[j] = arreglo[j+1];
  14.                     arreglo[j+1] = temporal;
  15.                 }
  16.             }
  17.         }
  18.     }
  19. }
  20.  
  21.  
  22.  
  23.  
  24. import org.junit.Test;
  25. import org.junit.Assert;
  26.  
  27. public class PruebaBurbuja {
  28.  
  29.    
  30.     @Test
  31.     public void ordenar(){
  32.        
  33.         Burbujeo burbuja = new Burbujeo();
  34.         int[] arreglo = new int[] {2,12,5,24,1};
  35.        
  36.         burbuja.burbujeo(arreglo);
  37.        
  38.         for (int i = 0; i < arreglo.length; i++){
  39.            
  40.             System.out.println(arreglo[i]);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement