- Main Page
- Namespaces
- Files

- File List
- File Members

# C:/Musimathics_local/Musimat/MusimatChapter9/C091201c.cpp File Reference

`#include "MusimatChapter9.h"`

Go to the source code of this file.

## Functions
| MusimatChapter9Section (C091201c)
Integer | permute (IntegerList L, Integer Reference pos, Integer Reference count, Integer inc)
Static Void | para1 ()

## Function Documentation

MusimatChapter9Section | ( | C091201c |  | ) |

Definition at line 2 of file C091201c.cpp.

References para1().

    00002                                  {
    00003 Print("*** Permutation ***");
    00004 /*****************************************************************************
    00005
    00006 Permutation
    00007
    00008 Iterate the supplied sequence in prime order until exhausted, then permute the
    00009 entire row by inc steps and repeat from the beginning.
    00010 *****************************************************************************/
    00011         para1(); // Step into this function to continue.
    00012 }

Static Void para1 | ( |  | ) |

Definition at line 26 of file C091201c.cpp.

References permute().

    00026                     {
    00027 /*****************************************************************************
    00028 Here is an example of invoking permute().
    00029 *****************************************************************************/
    00030         Print("*** Permutation ***");
    00031         IntegerList L(10, 11, 12);
    00032         Integer inc = -1;
    00033         Integer pos = 0;
    00034         Integer perm = 0;
    00035
    00036         For (Integer i = 0; i < 3 * Length(L); i++)
    00037                         Print(permute(L, pos, perm, inc));
    00038
    00039 /*****************************************************************************
    00040 prints 10, 11, 12, 11, 12, 10, 12, 10, 11. Because inc = –1, it skips back one place in the
    00041 row every time. The trigger for it to skip is when it has output as many elements as are in the list.
    00042 *****************************************************************************/
    00043 }}

Integer permute | ( | IntegerList | L,
|  | Integer Reference | pos,
|  | Integer Reference | count,
|  | Integer | inc |
| ) |  |  |

Definition at line 14 of file C091201c.cpp.

References cycle(), and x.

    00015                                               {
    00016         Integer curPos = pos;                                                   // save current position
    00017         Integer x = cycle(L, pos, 1);                                   // update pos and get list value
    00018         count = count + 1;                                                              // increment counter
    00019         If (count == Length(L)){                                                // have we output L items from list?
    00020                 count = 0;                                                                      // reset count
    00021                 pos = curPos + inc;                                                     // permute position for next time
    00022         }
    00023         Return(x);
    00024 }