Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package first;
  7.  
  8. /**
  9. *
  10. * @author admin
  11. */
  12. public class First {
  13.  
  14.  
  15. public void bubbleSort(int[] arr) {
  16. boolean swapped = true;
  17. while(swapped) {
  18. swapped = false;
  19. for(int i = 0; i < arr.length - 1; i++) {
  20. if(arr[i] > arr[i + 1]) {
  21. int temp = arr[i];
  22. arr[i] = arr[i + 1];
  23. arr[i + 1] = temp;
  24. swapped = true;
  25. }
  26. }
  27. }
  28.  
  29. }
  30.  
  31. /**
  32. * @param args the command line arguments
  33. */
  34. public static void main(String args[]) {
  35.  
  36. First s = new First();
  37. int[] arr = new int[] {7,2,0,4,5,6,9,1,3,8};
  38. s.bubbleSort(arr);
  39. for(int i = 0; i < arr.length; i++) {
  40. System.out.print(arr[i] + " ");
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement