Basically I’m trying to create a BASIC sorting program in ruby without using .sort .
Here’s my code so far:
def optsort
@@a = 0
@@aa= 1
@@b = unsorted.size
@@smallestnum
@@ssmallestnum
while b !=1
if unsorted[a] <= unsorted[b] then
@@smallestnum = unsorted[b]
else @@smallestnu = unsorted[a]
end
@@a = @@a +
@@aa = @@a + 1
b = b - 1
end
Please help me with the code.
ALSO: I get those error messages when I run it:
(eval):465: (eval):465: compile error (SyntaxError)
(eval):465: syntax error, unexpected $end, expecting kEND
The code is supposed to sort the numbers from least to greatest.
That little
^points to first problem here.<<==is not a legal operator in ruby, hence the syntax error. Perhaps you mean “less than or equal to” which is<=?Also, indentation will help you understand the flow better, try rewriting that like this: