Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created September 3, 2012 20:05
Show Gist options
  • Save kmandreza/3612955 to your computer and use it in GitHub Desktop.
Save kmandreza/3612955 to your computer and use it in GitHub Desktop.
Sort an Array
#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