Sorting algorithms/Bubble sort: Difference between revisions

Content added Content deleted
Line 859: Line 859:


=={{header|Ruby}}==
=={{header|Ruby}}==
Although the native Ruby sort method for Arrays if much faster (O(n*log(n)) versus O(n**2)), you can find a Ruby version of Bubble sort hereunder. It adds the bubblesort! method to the Array object. Below are two different methods that show four different iterating constructs in ruby.
{{eff note|Ruby|Array.sort!}}This example adds the bubblesort! method to the Array object. Below are two different methods that show four different iterating constructs in ruby.


<lang ruby> class Array
<lang ruby> class Array