diff --git a/sorting/sort_color.rb b/sorting/sort_color.rb index e1cb3a1..fd428ee 100644 --- a/sorting/sort_color.rb +++ b/sorting/sort_color.rb @@ -34,12 +34,14 @@ def bubble_sort(array) loop do swapped = false + (array_length - 1).times do |i| if array[i] > array[i + 1] array[i], array[i + 1] = array[i + 1], array[i] swapped = true end end + break unless swapped end