Permutations: Difference between revisions

m
m (→‎{{header|Perl}}: typo fix.)
Line 1,292:
=={{header|Eiffel}}==
<lang Eiffel>
 
permute(a: ARRAY[INTEGER]; k: INTEGER)
class
require
APPLICATION
ar_not_void: a.count>=1
 
k_valid_index: k>0
create
local
make
i,t: INTEGER
 
do
feature {NONE} -- Initialization
if k=a.count then
 
across a as ar loop io.put_string (ar.item.out) end
make
io.put_string ("%N")
do
else
test := << 2, 5, 1>>
from
permute (test, 1)
i:= k
untilend
 
i> a.count
i,t test: ARRAY [INTEGER]
loop
 
t:= a[k]
permute (a: ARRAY [INTEGER]; k: INTEGER)
a[k]:= a[i]
require
a[i]:= t
count_positive: a.count > 0
permute(a,k+1)
tk_valid_index:= a[k] > 0
local
a[k]:= a[i]
a[i]t:= tINTEGER
do
i:= i+1
if k = a.count then
across
a as ar
loop
io.put_integer (ar.item)
end
io.new_line
else
across
i> k |..| a.count as c
loop
i t := a [k]
a [k] := a [ic.item]
a [ic.item] := t
permute (a, k + 1)
t := a [k]
a [k] := a [ic.item]
a [c.item] := t
end
end
end
end
make
do
test:= << 2,5,1>>
permute(test, 1)
end
test: ARRAY[INTEGER]
 
end
 
</lang>
{{out}}
Anonymous user