ssdcua
Last Updated: August 19, 2018
·
989
· 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]

Say Thanks
Respond

18 Responses
Add your response

29293
Article 2371334 1ae7450d000005dc 684 634x421

Oh thanks for bubble sort in ruby really thanks man

11 months ago ·
29587

thanks

7 months ago ·
29588

bubble sort mark

7 months ago ·
29728
12 1510738735134

what is the advantage of this over single and multi-line commenting by clicking the line number, or selecting multiple lines then pressing "command(or ctrl) + /"?

Read manga online for free in high quality and most full at MangaFox: https://manga-fox.com/

6 months ago ·
29739
Wp themes india   copy

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

5 months ago ·
29914

Thanks for share with me this information http://www.geometrydash.me/

3 months ago ·
30045

this is correct? if array[i] > array[i + 1]
array[i], array[i + 1] = array[i + 1], array[i]?
https://y8.world

about 2 months ago ·
30124

I like this article, it is very meaningful and detailed, I hope you will have many good articles like this to share.
https://colorswitchaz.com

about 1 month ago ·
30197
about 1 month 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/

about 1 month 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

28 days ago ·
30239
24 days ago ·
30287

Thanks for share with me this information https://kenthabergazetesi.com/

14 days ago ·
30288

Casinomaxi ile güvenilir bahis keyfi yaşayın https://casinomaxis.com/

14 days ago ·
30296

Oh thanks for bubble sort in ruby really thanks man

https://www.artemisbet6000.com/

13 days ago ·
30365

Betconstruct alt yapılı Betmoon bahis sitesi Curacao lisansına sahiptir. Bahis sektöründe yer alan en güvenilir hizmetler Betmoon bahis şirketinde yer almaktadır. https://www.efsanelermeydani.com/betmoon-giris/

7 days ago ·
30405

İlbet giriş ve adres değişikliği bildirimlerini alın. İlbet giriş adresi https://ilbet.net/

3 days ago ·
30406
2 days ago ·