Skip to content

Instantly share code, notes, and snippets.

@worace
Created February 16, 2016 17:20
Show Gist options
  • Save worace/ed79e8496ffe9c488fc8 to your computer and use it in GitHub Desktop.
Save worace/ed79e8496ffe9c488fc8 to your computer and use it in GitHub Desktop.
class BubbleSort
def initialize
@num_times = 0
end
def bubble_sort(array)
array_size = array.length
have_swapped_this_round = false
swap_numbers(array, array_size)
array
end
# true/false
# Pass by value
def swap_numbers(array,array_size)
# scoping and when a variable is available
# in a given context
# and when to distinguish variables that have the
# same name in different contexts
(array_size - 1).times do |index|
puts "wooo times #{@num_times}"
@num_times += 1
if array[index] > array[index+1]
array[index], array[index+1] = array[index+1], array[index]
bubble_sort(array)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment