class Array

Public Instance Methods

bubble_sort() click to toggle source
# File lib/P10/modified_array.rb, line 2
def bubble_sort
    i = 0
    j = 0
    v_aux = self.clone
    while j < v_aux.size-1 do 
      while i < v_aux.size-1 do 
        if v_aux[i] > v_aux[i+1] 
            aux = v_aux[i]
            v_aux[i] = v_aux[i+1]
            v_aux[i+1] = aux
        end
        
        i = i+1
      end
      j = j+1
      i = 0
    end
    
    v_aux
end
bubble_sort_func() click to toggle source
# File lib/P10/modified_array.rb, line 23
def bubble_sort_func
    self_ = self.clone
    aux = self.clone
    (0..self.size-1).each{|x| min = self_.min; prev = aux[x]; aux[x] = min; self_.delete(min)}
    aux
end