Data Structures, Algorithms, & Applications in C++
Chapter 5, Exercise 9
The code is given below and in the file
arrayListWithOverloadNotEqual.h. Test code is
included in arrayListWithOverloadNotEqual.cpp.
template<class T>
class arrayListWithOverloadNotEqual : public arrayList<T>
{
public:
// constructor and destructor
arrayListWithOverloadNotEqual(int initialCapacity = 10)
: arrayList<T> (initialCapacity) {}
bool operator!=(const arrayListWithOverloadNotEqual<T>& theList) const;
};
template<class T>
bool arrayListWithOverloadNotEqual<T>::operator!=(const arrayListWithOverloadNotEqual<T>& theList) const
{// Return true iff the two lists are not identical.
if (listSize != theList.listSize)
return true;
// check the elements
for (int i = 0; i < listSize; i++)
if (element[i] != theList.element[i])
return true;
return false;
}