Source of writeBackward.cpp


  1: //  Created by Frank M. Carrano and Tim Henry.
  2: //  Copyright (c) 2013 __Pearson Education__. All rights reserved.

  4: /** Writes a character string backward.
  5:  @pre  The string s to write backward.
  6:  @post  None.
  7:  @param s  The string to write backward. */
  8: void writeBackward(string s)
  9: {
 10:    int length = (int)s.size(); // Length of string
 11:    if (length > 0)
 12:    {
 13:       // Write the last character
 14:       cout << s.substr(length - 1, 1);
 15:       
 16:       // Write the rest of the string backward
 17:       writeBackward(s.substr(0, length - 1)); // Point A
 18:    } // end if
 19:    
 20:    // length == 0 is the base case - do nothing
 21: }  // end writeBackward