This function returns the next permuation of the multiset if there is one. initMC called before nextPerm can be called.

nextPerm(mcObj)

Arguments

mcObj

an S3 object of class mc which must be created with initMC

Value

either a vector with the next permutation of the multiset or FALSE when all permutations have been returned

See also

nextPerm

Author

James M. Curran

Examples


x = c(1,1,2,2)
m1 = initMC(x)

for(i in 1:6){
  cat(paste(paste(nextPerm(m1),collapse=","),"\n"))
}
#> 2,2,1,1 
#> 1,2,2,1 
#> 2,1,2,1 
#> 1,2,1,2 
#> 1,1,2,2 
#> 2,1,1,2 

## an example with letters
x = letters[1:4]
m2 = initMC(x)
nextPerm(m2)
#> [1] "d" "c" "b" "a"
nextPerm(m2)
#> [1] "a" "d" "c" "b"
## and so on