Advertisement
korobushk

bBSort

Mar 21st, 2021
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1.   public static void bBSort(int[] arr)              //int[] arr = {64, 34, 25, 12, 22, 11, 90};
  2.     {
  3.         int n = arr.length;
  4.  
  5.         for(int i=0;i<n-1;i++)       //  0
  6.         {
  7.             for(int j = 0; j<n-i-1; j++)    //0 1 2 3 4 5 6| 0 1 2 3 4 5| 0 1 2 3 4| 0 1 2 3 | 0 1 2| 0 1|
  8.             {
  9.                 if(arr[j]>arr[j+1])             /// 64 > 34             |   64>25  
  10.                 {
  11.                     int temp = arr[j];          // temp = 64            | temp = 64
  12.                     arr[j] = arr[j+1];          // arr[0] = 34          | arr[1] = 25
  13.                     arr[j+1] = temp;            // arr[1] = 64          | arr[2] = 64
  14.                 }                               //34,64,25,12,22,11,90  | 34,25,64,12,22,11,90    // sort
  15.             }
  16.         }
  17.     }
  18.  
  19. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement