Data Structures, Algorithms, & Applications in C++
Chapter 5, Exercise 13
The code is given below and in the file
arrayListWithSwap.h. Test code is
included in arrayListWithSwap.cpp.
The function name has been changed to swap1 because the
C++ compiler couldn't dismabiguate the newly defined function and the standard
two parameter swap function of C++.
template<class T>
class arrayListWithSwap : public arrayList<T>
{
public:
// constructor and destructor
arrayListWithSwap(int initialCapacity = 10)
: arrayList<T> (initialCapacity) {}
void swap1(arrayListWithSwap<T>& theList);
};
template<class T>
void arrayListWithSwap<T>::swap1(arrayListWithSwap<T>& theList)
{// Swap the two lists.
swap(arrayLength, theList.arrayLength);
swap(listSize, theList.listSize);
swap(element, theList.element);
}