Guest User

Untitled

a guest
Dec 11th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. /**
  2. * 冒泡排序
  3. * @author lcw20
  4. *
  5. */
  6. public class BubbleSort {
  7.  
  8. public static void sort(int[] arr) {
  9.  
  10. for (int i = 0; i < arr.length; i++) {
  11. for (int j = i+1; j < arr.length; j++) {
  12. if (arr[i] > arr[j]) {
  13. int temp = arr[i];
  14. arr[i] = arr[j];
  15. arr[j] = temp;
  16. }
  17. }
  18.  
  19. }
  20. }
  21.  
  22. public static void main(String[] args) {
  23.  
  24. int[] arr = new int[] {6,3,2,4,1};
  25. sort(arr);
  26. for (int i = 0; i < arr.length; i++) {
  27. System.out.println(arr[i]);
  28. }
  29. }
  30.  
  31. }
Add Comment
Please, Sign In to add comment