I\'m trying to use the bubble sort method to sort an array of only three numbers. The code I\'m using is below.
def my_sort(list) return list if list.
What worked for me, is below.
def my_sort(list) n = list.length loop do swapped = false (n-1).times do |i| if list[i] > list[i+1] list[i], list[i+1] = list[i+1], list[i] swapped = true end end break if not swapped end list end