June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
41
Task/Permutations/Fortran/permutations-4.f
Normal file
41
Task/Permutations/Fortran/permutations-4.f
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
program nptest
|
||||
integer n,i,a
|
||||
logical nextp
|
||||
external nextp
|
||||
parameter(n=4)
|
||||
dimension a(n)
|
||||
do i=1,n
|
||||
a(i)=i
|
||||
enddo
|
||||
10 print *,(a(i),i=1,n)
|
||||
if(nextp(n,a)) go to 10
|
||||
end
|
||||
|
||||
function nextp(n,a)
|
||||
integer n,a,i,j,k,t
|
||||
logical nextp
|
||||
dimension a(n)
|
||||
i=n-1
|
||||
10 if(a(i).lt.a(i+1)) go to 20
|
||||
i=i-1
|
||||
if(i.eq.0) go to 20
|
||||
go to 10
|
||||
20 j=i+1
|
||||
k=n
|
||||
30 t=a(j)
|
||||
a(j)=a(k)
|
||||
a(k)=t
|
||||
j=j+1
|
||||
k=k-1
|
||||
if(j.lt.k) go to 30
|
||||
j=i
|
||||
if(j.ne.0) go to 40
|
||||
nextp=.false.
|
||||
return
|
||||
40 j=j+1
|
||||
if(a(j).lt.a(i)) go to 40
|
||||
t=a(i)
|
||||
a(i)=a(j)
|
||||
a(j)=t
|
||||
nextp=.true.
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue