Question: Question: APPENDIX Using the library provided in Appendix, write in pseudocode the procedure permutation nextPermutation 2 (permutation p) which returns the next n-permutation in lexicographic
Question:
APPENDIX


Using the library provided in Appendix, write in pseudocode the procedure permutation nextPermutation 2 (permutation p) which returns the next n-permutation in lexicographic order after p, where n is the length of p (but p is not necessarily an n-permutation of 1..n). Return the empty string if p is the last n- permutation. For example, return (-3,1,11,5) if p=(-3,1,5,11) and return () if p=(11,5,1,3). APPENDIX void printCombination (combination c) Prints c. integer cardinalCombination (combination c) Returns the cardinal of c. integer elementCombination (integer i, combination c) Returns the ith term of the increasing n-permutation of c, where n is the cardinal of c. combination firstCombination (integer n) Returns the combination 1..n. combination nextCombination (integer n, combination c) Assumes c is a combination of 1..n. Returns the next r-combination in lexicographic order after c, where r is the cardinal of c. Returns the empty set if c is the last r-combination of 1..n. void printPermutation (permutation p) Prints p. iel..n. integer lengthPermutation (permutation p) Returns the length of p. integer termPermutation (integer i, permutation p) Returns the ith term of p. permutation firstPermutation (integer n) Returns the permutation (i)ie permutation nextPermutation (permutation p) Assumes p is an n-permutation of 1..n. Returns the next n-permutation in lexicographic order after p. Returns the empty string if p is the last n-permutation of 1..n. permutation sortPermutation (permutation p) Returns the permutation (qi)iel.n of 1..n, where n is the length of p, such that pi is the qih smaller term of p. For example, returns (3,2,4,1) if p=(5,-3, 99,12). permutation rearrangePermutation (permutation p, permutation q) Assumes that q is an n-permutation of 1..n, where n is the length of p. Returns the n-permutation whose ith term is the qith smaller term of p. For example, returns (-3,5,-12,99) if p=(5,-3, 99,-12) and q=(2,3,1,4). permutation combination ToPermutation (combination c) Returns the increasing n-permutation of c, where n is the cardinal of c. integer intercityDistance (integer i, integer ;) Returns the distance between the two cities Ci and Cj
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
