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) const
6: {
7: bool isFound = false;
8: int result = -1;
9: int searchIndex = 0;
10:
11: // If the bag is empty, itemCount is zero, so loop is skipped
12: while (!isFound && (searchIndex < itemCount))
13: {
14: isFound = (items[searchIndex] == target);
15: if (isFound)
16: {
17: result = searchIndex;
18: }
19: else
20: {
21: searchIndex++;
22: } // end if
23: } // end while
24:
25: return result;
26: } // end getIndexOf