Last active
August 29, 2015 14:23
-
-
Save Momozono/28046779dc85341e9a9c to your computer and use it in GitHub Desktop.
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
array = [] | |
print "配列の数を指定してください:"; n = gets.chomp.to_i | |
print "最大の数を指定してください:"; r = gets.chomp.to_i | |
n.times do | |
array << rand(r) | |
end | |
count = array.length | |
def compare(left,right) | |
left <=> right | |
end | |
while count != 0 | |
num1 = array.length - 1 | |
num2 = num1 - 1 | |
while num1 != 0 | |
left = array[num2] | |
right = array[num1] | |
if compare(left,right) == 1 #戻り値1で左が大きい | |
array[num1], array[num2] = array[num2], array[num1] | |
end | |
num1 -= 1 | |
num2 -= 1 | |
end | |
count -= 1 | |
end | |
print array |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment