Created
February 16, 2016 17:20
-
-
Save worace/ed79e8496ffe9c488fc8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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