Sha256: 14c6aeb3b968398f59759d712b3982e838f819d3f18113c3fe8275316d4a897b

Contents?: true

Size: 380 Bytes

Versions: 1

Compression:

Stored size: 380 Bytes

Contents

puts "Bubble Sort"
puts "-----------------"
lista = [18, 7, 55, 23, 1, 12, 57, 85, 42]

def BubbleSort(lista)
  n = lista.length
  troca = true

  while troca
    troca = false
    for i in 0..n-2
      if lista[i] > lista[i + 1]
        lista[i], lista[i + 1] = lista[i + 1], lista[i]
        troca = true
      end
    end
    n -= 1
  end
  
  puts lista
end

BubbleSort(lista)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
algoritmos-0.1.0 lib/BubbleSort.rb