Class: Bublle_sort
- Inherits:
-
Object
- Object
- Bublle_sort
- Defined in:
- lib/Algoritimos_fase1/bubble_sort.rb
Instance Attribute Summary collapse
-
#arr ⇒ Object
Returns the value of attribute arr.
Instance Method Summary collapse
- #bubble_sort(arr) ⇒ Object
-
#initialize ⇒ Bublle_sort
constructor
A new instance of Bublle_sort.
Constructor Details
#initialize ⇒ Bublle_sort
Returns a new instance of Bublle_sort.
3 4 5 |
# File 'lib/Algoritimos_fase1/bubble_sort.rb', line 3 def initialize @arr = arr end |
Instance Attribute Details
#arr ⇒ Object
Returns the value of attribute arr.
2 3 4 |
# File 'lib/Algoritimos_fase1/bubble_sort.rb', line 2 def arr @arr end |
Instance Method Details
#bubble_sort(arr) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/Algoritimos_fase1/bubble_sort.rb', line 7 def bubble_sort(arr) arr.each_index do |i| max_index = arr[i..-1].each_with_index.min_by { |num, _| num }[1] + i arr[i], arr[max_index] = arr[max_index], arr[i] true end arr end |