Advertisement
urksiful

BubleSort

Nov 7th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.89 KB | None | 0 0
  1.  
  2.  
  3. /**
  4.  *
  5.  * @author urksiful
  6.  */
  7. import java.util.ArrayList;
  8.  
  9. public class BubleSort {
  10.    
  11.     public static void main(String[] args) {
  12.         ArrayList<Integer> arreglo = new ArrayList<Integer>();
  13.        
  14.         for(int i=0; i<100; i++){
  15.            arreglo.add((int)(Math.random()*200)+1);
  16.             System.out.print(arreglo.get(i)+" ");
  17.         }
  18.         int aux;
  19.        
  20.         for(int i=0; i<100-2; i++){
  21.             for(int j=0; j<100-1; j++){
  22.                 if(arreglo.get(j+1)<arreglo.get(j)){
  23.                    
  24.                     aux = arreglo.get(j);
  25.                     arreglo.set(j, arreglo.get(j+1));
  26.                     arreglo.set(j+1, aux);
  27.                    
  28.                 }
  29.             }
  30.         }
  31.         System.out.println("");
  32.          for(int i=0; i<100; i++){
  33.             System.out.print(arreglo.get(i)+" ");
  34.         }
  35.     }
  36.    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement