#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 () |
MusimatChapter9Section | ( | C091201b | ) |
Definition at line 2 of file C091201b.cpp.
References para1().
{ Print("*** Palindrome ***"); /***************************************************************************** Palindrome We can iterate a sequence in prime order until the last element in the sequence is reached, then iterate the sequence retrograde until the first element in the sequence is reached, then repeat. *****************************************************************************/ para1(); // Step into this function to continue. }
Integer palindrome | ( | IntegerList | L, |
Integer Reference | pos, | ||
Integer Reference | inc | ||
) |
Definition at line 15 of file C091201b.cpp.
References cycle().
{ Integer curPos = pos; Integer x = cycle(L, pos, inc); If (curPos + inc != pos){ inc = inc * (-1); // change direction pos = curPos; } Return(x); }
Static Void para1 | ( | ) |
Definition at line 25 of file C091201b.cpp.
References palindrome().
{ /***************************************************************************** This method calls cycle() to do most of its work. Like cycle(), this method updates pos, but it also must update its increment argument, inc, because whenever it hits the end of the list, we want it to reverse the direction of traversal rather than start over. The extra work done by this method is to change the increment and reset the position when either end of the list is reached. Here is an example of invoking palindrome(). *****************************************************************************/ Print("*** Palindrome ***"); IntegerList L(10, 11, 12); Integer myPos = 0; Integer myInc = 1; // can be any positive or negative integer For (Integer i = 0; i < 2 * Length(L); i = i + 1) { Print(palindrome(L, myPos, myInc)); } /***************************************************************************** prints 10, 11, 12, 12, 11, 10. Note that the end of the list is printed twice. This makes it a so-called even palindrome. It would be an odd palindrome if it were 10, 11, 12, 11, 10. It is left as an exercise for the reader to adapt palindrome() to generate odd palindromes. *****************************************************************************/ }