c----------------------------------------------------------- c Chapter 11: Next partition of an n-set(p91) c----------------------------------------------------------- c Name of subroutine: NEXEQU c c Algorithm:Generating next equivalence relation on c {1,2,...,n} c c input: n=5 c compiler: f77 nexequ_2.f c----------------------------------------------------------- parameter(n=5) logical mtc integer p(n),q(n) integer nc,n mtc=.false. 20 call nexequ(n,nc,p,q,mtc) write(*,40), (q(i),i=1,5) 40 format(1x,5(i2,1x)) if(mtc)goto 20 stop end c-----Subroutine begins here-------------------------------- subroutine nexequ(n,nc,p,q,mtc) logical mtc integer p(n),q(n) data nlast/0/ 10 if(n.eq.nlast) go to 20 30 nlast=n nc=1 do 35 i=1,n 35 q(i)=1 p(1)=n 40 mtc=(nc.ne.n) return 20 if(.not.mtc) go to 30 70 m=n 80 l=q(m) 90 if(p(l).ne.1) go to 100 95 q(m)=1 m=m-1 go to 80 100 nc=nc+m-n p(1)=p(1)+n-m 110 if(l.ne.nc) go to 130 120 nc=nc+1 p(nc)=0 130 q(m)=l+1 p(l)=p(l)-1 p(l+1)=p(l+1)+1 go to 40 end