Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public void bubbleSort(int a[]) {
  2. int size = a.length;
  3. for(int i=size-1; i>0; i--) {
  4. System.out.printf("\n버블 정렬 %d 단계 : ", size-i);
  5. for(int j=0; j<i; j++) {
  6. if(a[j] > a[j+1]) {
  7. swap(a,j,j+1);
  8. }
  9. System.out.printf("\n\t");
  10. for(int v : a) {
  11. System.out.printf("%3d ", v);
  12. }
  13. }
  14. }
  15. System.out.println();
  16. }
  17. public void swap(int a[], int idx1, int idx2) {
  18. int temp = a[idx1];
  19. a[idx1] = a[idx2];
  20. a[idx2] = temp;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement