Jump to content

Sorting algorithms/Bogosort: Difference between revisions

m
Line 465:
=={{header|Eiffel}}==
<lang Eiffel>
 
class
BOGO_SORT
Line 506 ⟶ 505:
end
 
shuffelshuffle (ar: ARRAY [INTEGER]): ARRAY [INTEGER]
-- Array containing the same elements as 'ar' in a random shuffled order.
require
not_voidmore_than_one_element: ar.count /=> Void1
local
icount, j, ith: INTEGER
ith: INTEGER
random: V_RANDOM
do
Line 518 ⟶ 516:
create Result.make_empty
Result.deep_copy (ar)
icount := ar.count
from
across
i := ar.count
1 |..| count as c
until
i < 2
loop
j := random.bounded_item (1c.item, icount)
ith := Result [ic.item]
Result [ic.item] := Result [j]
Result [j] := ith
random.forth
i := i - 1
end
ensure
same_elements: across ar as a all Result.has (a.item) end
end
 
Line 544 ⟶ 542:
make
 
feature {NONE} -- Initialization
 
make
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.