jaVer404

Buuble_sorting

Apr 13th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. /*сверху вниз*/    
  2. public static void sort(int[] array)
  3.     {
  4.         //Напишите тут ваш код
  5.         int j;
  6.         boolean flag = true;
  7.         int temp;
  8.         while (flag) {
  9.             flag = false;
  10.             for (j = 0; j < array.length - 1; j++) {
  11.                 if (array[j] < array[j+1]) {
  12.                     temp = array[j];
  13.                     array[j] = array [j + 1];
  14.                     array[j + 1] = temp;
  15.                     flag = true;
  16.                 }
  17.             }
  18.          }
  19.     }
  20.  
  21. /*===================================================*/
  22. /*cнизу вверх*/    
  23. public static void sort(int[] array)
  24.     {
  25.         //Напишите тут ваш код
  26.         int j;
  27.         boolean flag = true;
  28.         int temp;
  29.         while (flag) {
  30.             flag = false;
  31.             for (j = 0; j < array.length - 1; j++) {
  32.                 if (array[j] > array[j+1]) {
  33.                     temp = array[j];
  34.                     array[j] = array [j + 1];
  35.                     array[j + 1] = temp;
  36.                     flag = true;
  37.                 }
  38.             }
  39.          }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment