Created
September 3, 2012 20:05
-
-
Save kmandreza/3612955 to your computer and use it in GitHub Desktop.
Sort an Array
This file contains 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
#Given a random array, create a method that sorts the array so the numbers are returned in order. | |
a= [5, 8, 3, 2, 7, 4, 1, 0, 9, 6, 10, 55] | |
#Final Answer | |
def singlesort(a) | |
(a.size - 1).times do |i| | |
if a[i] > a[i+1] | |
x=a[i] | |
a[i] = a[i+1] | |
a[i+1] = x | |
end | |
end | |
a | |
end | |
def kharasort(a) | |
a.each do |i| | |
singlesort(a) | |
end | |
a | |
end | |
#How I got there... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment