Sorting algorithms/Bubble sort: Difference between revisions
Content added Content deleted
(→{{header|Eiffel}}: Removed "beta" from version 6.6) |
(Fixed Java Code) |
||
Line 845: | Line 845: | ||
<lang java>do { |
<lang java>do { |
||
boolean changed = false; |
boolean changed = false; |
||
for (int a = 0; a < comparable.length - |
for (int a = 0; a < comparable.length - 1; a++) { |
||
if (comparable[a].compareTo(comparable[a + 1]) > 0) { |
if (comparable[a].compareTo(comparable[a + 1]) > 0) { |
||
int tmp = comparable[a]; |
int tmp = comparable[a]; |
||
Line 853: | Line 853: | ||
} |
} |
||
} |
} |
||
} while ( |
} while (changed);</lang> |
||
For descending, simply switch the direction of comparison: |
For descending, simply switch the direction of comparison: |