Sorting algorithms/Bogosort: Difference between revisions
Content added Content deleted
m (→{{header|Java}}: nl after works with) |
(add E example) |
||
Line 331: | Line 331: | ||
writefln("%s", b) ; // sort is in place |
writefln("%s", b) ; // sort is in place |
||
}</lang> |
|||
=={{header|E}}== |
|||
Using the shuffle from [[Knuth shuffle#E]]. |
|||
<lang e>def isSorted(list) { |
|||
if (list.size() == 0) { return true } |
|||
var a := list[0] |
|||
for i in 1..!(list.size()) { |
|||
var b := list[i] |
|||
if (a > b) { return false } |
|||
a := b |
|||
} |
|||
return true |
|||
} |
|||
def bogosort(list, random) { |
|||
while (!isSorted(list)) { |
|||
shuffle(list, random) |
|||
} |
|||
}</lang> |
}</lang> |
||