tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
34
Task/Permutation-test/Ada/permutation-test-3.ada
Normal file
34
Task/Permutation-test/Ada/permutation-test-3.ada
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package body Iterate_Subsets is
|
||||
|
||||
function First return Subset is
|
||||
S: Subset;
|
||||
begin
|
||||
for I in S'Range loop
|
||||
S(I) := I;
|
||||
end loop;
|
||||
return S;
|
||||
end First;
|
||||
|
||||
procedure Next(S: in out Subset) is
|
||||
I: Natural := S'Last;
|
||||
begin
|
||||
if S(I) < Index'Last then
|
||||
S(I) := S(I) + 1;
|
||||
else
|
||||
while S(I-1)+1 = S(I) loop
|
||||
I := I - 1;
|
||||
end loop;
|
||||
S(I-1) := S(I-1) + 1;
|
||||
for J in I .. S'Last loop
|
||||
S(J) := S(J-1) + 1;
|
||||
end loop;
|
||||
end if;
|
||||
return;
|
||||
end Next;
|
||||
|
||||
function Last(S: Subset) return Boolean is
|
||||
begin
|
||||
return S(S'First) = Index'Last-S'Length+1;
|
||||
end Last;
|
||||
|
||||
end Iterate_Subsets;
|
||||
Loading…
Add table
Add a link
Reference in a new issue