How does one implement a bubble sort algorithm for a hash?
Thanks
How does one implement a bubble sort algorithm for a hash?
Thanks
Justin To wrote:
How does one implement a bubble sort algorithm for a hash?
One does not as hashes are unordered and thus not sortable.
HTH,
Sebastian
Ah, I see! Thanks
Sebastian H. wrote:
One does not as hashes are unordered and thus not sortable.
Well if the keys can be ordered (e.g. are Comparable), the hash can be
sorted by keys. If the values can be ordered, the hash can be sorted by
values. Which you do depends on your requirements.
Justin To wrote:
How does one implement a bubble sort algorithm for a hash?
If you want to write your own sort, you should know that bubble sorts
are deprecated. To get a good view of types of sorting algorithms, try
looking at http://www.cs.ubc.ca/spider/harrison/Java/sorting-demo.html
as they have show and tell with source code. Granted it is java, but
you can translate.
bubble_sort == bad
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs