Source of writeArrayBackward.cpp


  1: //  Created by Frank M. Carrano and Timothy M. Henry.
  2: //  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

  4: /** Writes the characters in an array backward.
  5:  @pre  The array anArray contains size characters, where size >= 0.
  6:  @post  None.
  7:  @param anArray  The array to write backward.
  8:  @param first  The index of the first character in the array.
  9:  @param last  The index of the last character in the array. */
 10: void writeArrayBackward(const char anArray[], int first, int last)
 11: {
 12:    if (first <= last)
 13:    {
 14:       // Write the last character
 15:       std::cout << anArray[last];
 16:       
 17:       // Write the rest of the array backward
 18:       writeArrayBackward(anArray, first, last - 1);
 19:    }  // end if
 20:    
 21:    // first > last is the base case - do nothing
 22: }  // end writeArrayBackward