Advertisement
slik1977

BubbleSort+Benchmark+Evtyukhov

Feb 24th, 2022
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. package MyPackage;
  2.  
  3. import org.openjdk.jmh.annotations.*;
  4.  
  5. import java.util.concurrent.TimeUnit;
  6.  
  7. public class BubbleSort {
  8.     void bubbleSort(int arr[])
  9.     {
  10.         int n = arr.length;
  11.         for (int i = 0; i < n-1; i++)
  12.             for (int j = 0; j < n-i-1; j++)
  13.                 if (arr[j] > arr[j+1])
  14.                 {
  15.                     // swap arr[j+1] and arr[j]
  16.                     int temp = arr[j];
  17.                     arr[j] = arr[j+1];
  18.                     arr[j+1] = temp;
  19.                 }
  20.     }
  21.  
  22.  
  23.     void printArray(int arr[])
  24.     {
  25.         int n = arr.length;
  26.         for (int i=0; i<n; ++i)
  27.             System.out.print(arr[i] + " ");
  28.         System.out.println();
  29.     }
  30.  
  31.     public void ArraySort(){
  32.         var array = new int[1000];
  33.         for (int i = 0; i < 1000; i++)
  34.             array[i] = 1000 - i;
  35.         bubbleSort(array);
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement