Posted By

jsmith on 01/10/12


Tagged

sort java algorithm bubble-sort sort-algorithm


Versions (?)

Bubble Sort


 / Published in: Java
 

  1. public void bubbleSort(int[] arr) {
  2. boolean swapped = true;
  3. int j = 0;
  4. int tmp;
  5. while (swapped) {
  6. swapped = false;
  7. j++;
  8. for (int i = 0; i < arr.length - j; i++) {
  9. if (arr[i] > arr[i + 1]) {
  10. tmp = arr[i];
  11. arr[i] = arr[i + 1];
  12. arr[i + 1] = tmp;
  13. swapped = true;
  14. }
  15. }
  16. }
  17. }

Report this snippet  

You need to login to post a comment.