Sorting algorithms/Bogosort: Difference between revisions

→‎{{header|Euphoria}}: Euphoria example added
(Added Nemerle)
(→‎{{header|Euphoria}}: Euphoria example added)
Line 426:
}
}</lang>
 
=={{header|Euphoria}}==
<lang euphoria>function shuffle(sequence s)
object temp
integer j
for i = length(s) to 1 by -1 do
j = rand(i)
if i != j then
temp = s[i]
s[i] = s[j]
s[j] = temp
end if
end for
return s
end function
 
function inOrder(sequence s)
for i = 1 to length(s)-1 do
if compare(s[i],s[i+1]) > 0 then
return 0
end if
end for
return 1
end function
 
function bogosort(sequence s)
while not inOrder(s) do
? s
s = shuffle(s)
end while
return s
end function
 
? bogosort(shuffle({1,2,3,4,5,6}))</lang>
 
Output:
<pre>{1,2,5,4,6,3}
{5,1,3,6,2,4}
{4,6,1,2,5,3}
.............
{1,2,6,5,4,3}
{5,3,1,2,6,4}
{1,2,3,4,5,6}
</pre>
 
=={{header|Factor}}==
Anonymous user