Created
March 27, 2012 15:18
-
-
Save jparedes/2216853 to your computer and use it in GitHub Desktop.
My RADIX sort implementation in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def radixSort(array) | |
| temp = Array.new | |
| array.each do |x| | |
| if temp[x] == nil | |
| temp[x] = 1 | |
| else | |
| temp[x] = temp[x] + 1 | |
| end | |
| end | |
| temp.each_with_index do |x, i| | |
| if (x) | |
| x.times do | |
| puts i | |
| end | |
| end | |
| end | |
| end | |
| def run() | |
| test = [9,8,7,5,5,5,4,3,1] | |
| radixSort(test) | |
| end | |
| run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment