# Bubble Sort in ruby.
def bubble_sort(array)
for i in 0..array.length - 1
for j in 0..array.length - 2
if array[j] > array[j+1]
array[j],array[j+1] = array[j+1],array[j]
end
end
end
end
array = [6,5,3,1,8,7,2,4]
bubble_sort array
print array
def bubble_sort(array)
for i in 0..array.length - 1
for j in 0..array.length - 2
if array[j] > array[j+1]
array[j],array[j+1] = array[j+1],array[j]
end
end
end
end
array = [6,5,3,1,8,7,2,4]
bubble_sort array
print array
No comments:
Post a Comment