Sorting algorithms/Bubble sort: Difference between revisions

Line 255:
Just xs2 -> Just $ x:xs2
_bsort _ = Nothing
 
==[[Java]]==
[[Category:Java]]
Bubble sorting (ascending) the array "int nums[]":
for(int a = 0; a < nums.length - 1; a++){
for(int b = a + 1; b < nums.length; b++){
if(nums[a] > nums[b]){
int tmp = nums[a];
nums[a] = nums[b];
nums[b] = tmp;
}
}
}
 
For descending, simply switch the direction of comparison:
if(nums[a] < nums[b]){
...
}
 
==[[JavaScript]]==
Anonymous user