ssdcua
Last Updated: March 04, 2019
·
1.533K
· webcoderph

Bubble Sort in Ruby

def bubble_sort(array)
   n = array.length
   swapped = true
   while swapped do
     swapped = false
     (n - 1).times do |i|
       if array[i] > array[i + 1]
         array[i], array[i + 1] = array[i + 1], array[i]
     swapped = true
       end
     end
   end
   array 
end

arr = [2,3,100,3,5,4,10,7]

p bubble_sort(arr) # => [2, 3, 3, 4, 5, 7, 10, 100]

14 Responses
Add your response

29293

Oh thanks for bubble sort in ruby really thanks man

over 1 year ago ·
29587

thanks

over 1 year ago ·
29588

bubble sort mark

over 1 year ago ·
29739

Thanks for sharing bubble sort in ruby It will be more helpful for us as best webdesign company in India

over 1 year ago ·
30197
8 months ago ·
30198

Learn more about Cousins Day, celebrated on July 24. ... July 24, 2018 is also Amelia Earhart Day | National Tequila Day; July is National Grilling Month ...
https://www.rmrg.co/when-is-national-cousins-day-in-2018/

8 months ago ·
30224

Hello everyone welecome to http://basketballgames.io You are a basketball enthusiast !!! You want to get involved with an impressive basketball game or simply a game player. Have fun

8 months ago ·
30239
30887
5 months ago ·
30960

Thank you so much tipobet güncel giriş adresleri için http://betmobil.org/tipobet adresini ve http://yenigiris1.site/tipobet sitesini ziyaret edebilirsiniz.

5 months ago ·
31172

Youwin bahis şirketinin ilk ve tek türkçe destek platformu olan http://you.girisadresi7.com/ sitemizi takip edin sizlerde kaznaın.

4 months ago ·
31173

Mobilbahis şirketinin güncel giriş adreslerine " http://mobil.bedava30.xyz/ " sayfamızı ziyaret ederek ulaşabilir destek alabilirsiniz.

4 months ago ·
31777

Noter çalışma saatleri 2018, kaçta açılıyor, kaçta kapanıyor, noter çalışma saatleri Ankara 2019, noter çalışma saatleri bursa, noter çalışma saatleri izmir, noter çalışma saatleri istanbul 2019, noter çalışma saatleri antalya, noter çalışma saatleri konya gibi detaylar yazımızda yer almaktadır.

https://www.paraysa.com/noter-calisma-saatleri

about 1 month ago ·
32024

Hello, just wanted to say, I loved this article. It was practical.
http://fnafgame.net

12 days ago ·