Sorting algorithms/Bogosort: Difference between revisions

Added Easylang
(→‎Insitux: correction)
(Added Easylang)
 
(3 intermediate revisions by 2 users not shown)
Line 798:
}
}</syntaxhighlight>
 
=={{header|BASIC256}}==
{{trans|FreeBASIC}}
</syntaxhighlight lang="vb">global array
dim array = {10, 1, 2, -6, 3}
lb = array[?,]-1 : ub = array[?]-1
 
print "unsort ";
for i = lb to ub
print rjust(array[i], 4);
next i
 
call Bogosort(array) # ordenar el array
 
print achr(i10),; " sort ";
for i = lb to ub
print rjust(array[i], 4);
next i
end
 
subroutine shuffle(array)
n = array[?] : m = array[?]*2
 
for k = 1 to m
i = int(Rand*n)
j = int(Rand*n)
tmp = array[i] #swap lb(i), lb(j)
array[i] = array[j]
array[j] = tmp
next k
end subroutine
 
function inorder(array)
n = array[?]
for i = 0 to arraysize(a(),1) n- 12
if array[i] > array[i+1] then return false
next i
return true
end function
 
subroutine Bogosort(array)
while not inorder(array)
call shuffle(array)
end while
end subroutine</syntaxhighlight>
 
=={{header|BBC BASIC}}==
Line 1,140 ⟶ 1,185:
}
}</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
proc shuffle . l[] .
for i = len l[] downto 2
r = randint i
swap l[i] l[r]
.
.
proc issorted . l[] r .
for i = 2 to len l[]
if l[i] < l[i - 1]
r = 0
return
.
.
r = 1
.
proc bogosort . l[] .
repeat
issorted l[] r
until r = 1
shuffle l[]
.
.
list[] = [ 2 7 41 11 3 1 6 5 8 ]
bogosort list[]
print list[]
</syntaxhighlight>
 
{{out}}
<pre>
[ 1 2 3 5 6 7 8 11 41 ]
</pre>
 
=={{header|Eiffel}}==
Line 3,504 ⟶ 3,583:
=={{header|Wren}}==
{{libheader|Wren-sort}}
<syntaxhighlight lang="ecmascriptwren">import "random" for Random
import "./sort" for Sort
 
var bogoSort = Fn.new { |a|
Line 3,553 ⟶ 3,632:
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">dim a(5)
a (0) = 10: a (1) = 1: a (2) = 2: a (3) = -6: a (4) = 3
 
Bogosort(a())
 
for i = 0 to arraysize(a(),1) - 1
print a(i), " ";
next i
end
 
sub shuffle(a())
n = arraysize(a(),1)
Line 3,571 ⟶ 3,659:
for i = 0 to n-2
if a(i) > a(i+1) then return false : fi
next i
return true
Line 3,580 ⟶ 3,668:
shuffle(a())
wend
end sub</syntaxhighlight>
 
dim a(5)
a (0) = 10: a (1) = 1: a (2) = 2: a (3) = -6: a (4) = 3
 
Bogosort(a())
 
for i = 0 to arraysize(a(),1) - 1
print a(i), " ";
next i
end
</syntaxhighlight>
 
 
=={{header|zkl}}==
2,017

edits