fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void bSort(int[] arr)
  11. {
  12. int n=arr.length;
  13. int c,i,t;
  14. while(true)
  15. {
  16. c=0;
  17. for (i=0; i<n-1; i++)
  18. {
  19. if (arr[i]>arr[i+1])
  20. {
  21. t=arr[i];
  22. arr[i]=arr[i+1];
  23. arr[i+1]=t;
  24. c++;
  25. }
  26. }
  27. if (c==0) break;
  28. }
  29. }
  30.  
  31. public static void main (String[] args) throws java.lang.Exception
  32. {
  33. int X[]={1,2,3,1,2,3,1,2,3,1,2,-3};
  34. bSort(X);
  35. for (int i=0; i<X.length; i++) System.out.print(X[i]+" ");
  36. }
  37. }
Success #stdin #stdout 0.09s 33684KB
stdin
Standard input is empty
stdout
-3 1 1 1 1 2 2 2 2 3 3 3