template <typename T> class ArrayList { private: unsigned int m_size; // current
ID: 3648491 • Letter: T
Question
template <typename T>class ArrayList
{
private:
unsigned int m_size; // current number of elements
unsigned int m_max; // maximum capacity of array m_data
T* m_data; // array to store the elements
T m_errobj; // object to return in case of error
public:
// Purpose: Default Constructor
// Postconditions: Current size and maximum size set to 0,
// and data set to NULL
// -- INLINE
ArrayList(): m_size(0), m_max(0), m_data(NULL) {};
emplate <typename T>
std::ostream& operator<< (std::ostream& out, const ArrayList<T>& alist)
{
out << "[ ";
for (unsigned int i=0; i < alist.m_size; i++){
out << alist.m_data[i] << ", ";
}
out << "]";
return out;
i need help setting up the members of the class
void swap(unsigned int i, unsigned int k);
// Purpose: appends two lists
// Parameters: alist, a list to append to the end of 'this' list
// Postconditions: current size is incremented by size of alist
// the elements of alist are appended to the elements of 'this'
void append(const ArrayList<T>& alist);
// Purpose: removes duplicates from an Arraylist
// Postconditions: all duplicate elements are removed from the list.
Explanation / Answer
#ifndef ARRAYLIST_H_ #define ARRAYLIST_H_ #include #include #include using namespace std; #ifndef uint #define uint unsigned int #endif template class ArrayList { protected: T * array; uint array_length; public: ~ArrayList(); ArrayList(); ArrayList(vector vect); ArrayList(uint num); ArrayList & operator= (const vector & vect); // ArrayList & operator= (const ArrayList & alist); void clear(); uint add(T obj); uint add(uint at, T obj); uint push_back(T obj); uint size(); T& at(uint index); T& get(uint index); T& operator[](uint index); void swap(uint loc1, uint loc2); void set(uint index, T obj); void remove(uint at); void erase(uint at); bool contains(T obj); uint indexOf(T obj); uint lastIndexOf(T obj); }; template ArrayList::~ArrayList() { if(array != NULL) free(array); } template ArrayList::ArrayList() { array_length = 0; array = NULL; } template ArrayList::ArrayList(vector vect) { array_length = vect.size(); array = (T *)calloc(array_length, sizeof(T)); for(uint i = 0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.