60 pts., due Mar. 1
In an attempt to discover a new secret code, a programmer thought of the
following scheme: ``I could divide a string into halves and interchange
them. In fact, I could do this recursively, dividing each half in half and
interchanging the pieces. That ought to mix up things pretty well.'' If
you think about it for a while, you'll discover another nice feature of
this scheme: the same algorithm can be used for coding and decoding.
- Write a C++ function which implements this function as described by
the programmer. Write a small driver program which allows you to test your
- Verify that your function can also decode a coded string.
- Unfortunately, this algorithm doesn't mix up the characters of a
string very well at all. What does the algorithm do? What would be the
result of applying this algorithm to the strings "alligator" and
"able was i ere i saw elba"?
- Write a simpler recursive function (and driver program) that does
what this function does.
Turn in copies of your source code and example runs with the input and
Thomas P. Kelliher
Mon Feb 19 17:37:09 EST 1996