Add a new method called \"contains\" to the array-based implementation of the li
ID: 3574547 • Letter: A
Question
Add a new method called "contains" to the array-based implementation of the list calss tamplate ArrayList. The specification for the method is
/** Sees wether a given entry occurs in a given list.
@param anEntry The object that is the desired entry.
@return true if the list contains anEntry, or false if not. */
bool contains(const ItemType& anEntry) const;
Reminder: the data members of the ArrayList class template are:
stactic const int DEFAULT_CAPACOTY = 5; //Initial list capacity
ItemType items[DEFAULT_CAPACITY +1] //Array of list items
int itemCount;
int maxItems;
Reminde
Explanation / Answer
Here is the code for contains() method:
bool contains(const ItemType& anEntry)
{
for(int i = 0; i < itemCount; i++)
if(items[i] == anEntry)
return true;
return false;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.