Sha256: b2862aa30e972399c3a9423483dcc7f0ac0c4305f1ea47e2df7408201e890254

Contents?: true

Size: 440 Bytes

Versions: 1

Compression:

Stored size: 440 Bytes

Contents

class Array
  def bubble_sort
    ary = self.dup
    (0...(ary.length - 1)).each { |i|
      ((i+1)...(ary.length)).reverse_each { |j|
        ary[j-1], ary[j] = ary[j], ary[j-1] if ary[j-1] > ary[j]
      }
    }
    ary
  end

  def bubble_sort!
    (0...(self.length - 1)).each { |i|
      ((i+1)...(self.length)).reverse_each { |j|
        self[j-1], self[j] = self[j], self[j-1] if self[j-1] > self[j]
      }
    }
    self
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nyuudou-1.0.3 lib/nyuudou/extension/array.rb