Guest User

Untitled

a guest
Apr 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. package Sorting;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class bubbleSort {
  6.  
  7. public static void swap(int[] x, int i, int j)
  8. {
  9. int temp = x[i];
  10. x[i] = x[j];
  11. x[j] = temp;
  12. }
  13.  
  14. public static void bubbleSort(int x[])
  15. {
  16. for (int j = 0; j < x.length -1; j++)
  17. {
  18. for (int i = 0; i < x.length - 1 - j; i++)
  19. {
  20. if (x[i] > x[i + 1])
  21. {
  22. swap(x, i, i + 1);
  23. }
  24. }
  25. }
  26. }
  27.  
  28.  
  29. public static void main(String[] args) {
  30. int x[] = {3, 2, 6, 8, 5, 1};
  31. bubbleSort(x);
  32. System.out.println(Arrays.toString(x));
  33. }
  34. }
Add Comment
Please, Sign In to add comment