C:/Musimathics_local/Musimat/MusimatChapter9/C091201b.cpp File Reference

#include "MusimatChapter9.h"

Go to the source code of this file.

Functions

 MusimatChapter9Section (C091201b)
Integer palindrome (IntegerList L, Integer Reference pos, Integer Reference inc)
Static Void para1 ()


Function Documentation

MusimatChapter9Section ( C091201b   ) 

Definition at line 2 of file C091201b.cpp.

References para1().

00002                                  {
00003 Print("*** Palindrome ***");
00004 /*****************************************************************************
00005 
00006 Palindrome
00007 
00008 We can iterate a sequence in prime order until the last element in the sequence is 
00009 reached, then iterate the sequence retrograde until the first element in the sequence is reached, then 
00010 repeat.
00011 *****************************************************************************/
00012         para1(); // Step into this function to continue.
00013 }

Integer palindrome ( IntegerList  L,
Integer Reference  pos,
Integer Reference  inc 
)

Definition at line 15 of file C091201b.cpp.

References cycle(), and x.

00015                                                                                 {
00016         Integer curPos = pos;
00017         Integer x = cycle(L, pos, inc);
00018         If (curPos + inc != pos){
00019                 inc = inc * (-1); // change direction
00020                 pos = curPos;
00021         }
00022         Return(x); 
00023 }

Static Void para1 (  ) 

Definition at line 25 of file C091201b.cpp.

References palindrome().

00025                     {
00026 /*****************************************************************************
00027 This method calls cycle() to do most of its work. Like cycle(), this method updates pos, 
00028 but it also must update its increment argument, inc, because whenever it hits the end of the list, 
00029 we want it to reverse the direction of traversal rather than start over. The extra work done by this 
00030 method is to change the increment and reset the position when either end of the list is reached. Here 
00031 is an example of invoking palindrome().
00032 *****************************************************************************/
00033 
00034         Print("*** Palindrome ***");
00035         IntegerList L(10, 11, 12);
00036         Integer myPos = 0;
00037         Integer myInc = 1; // can be any positive or negative integer
00038 
00039         For (Integer i = 0; i < 2 * Length(L); i = i + 1)
00040                         Print(palindrome(L, myPos, myInc));
00041 
00042 /*****************************************************************************
00043 prints 10, 11, 12, 12, 11, 10. Note that the end of the list is printed twice. This makes it a 
00044 so-called even palindrome. It would be an odd palindrome if it were 10, 11, 12, 11, 10. It is left 
00045 as an exercise for the reader to adapt palindrome() to generate odd palindromes.
00046 
00047 *****************************************************************************/
00048 }}


Generated on Fri Sep 8 23:11:08 2006 for Musimat Chapter 9 Code Examples by  doxygen 1.4.7