Source of getIndexOf.cpp


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

  4: template<class ItemType>
  5: int ArrayBag<ItemType>::getIndexOf(const ItemType& target, int searchIndex) const
  6: {
  7:    int result = -1;
  8:    if (searchIndex < itemCount)
  9:    {
 10:       if (items[searchIndex] == target)
 11:       {
 12:          result = searchIndex;
 13:       } 
 14:       else
 15:       {
 16:          result = getIndexOf(target, searchIndex + 1);
 17:       }  // end if
 18:    }  // end if
 19:    
 20:    return result;
 21: }  // end getIndexOf