Question: For each method in the ArrayList class template, determine the asymptotic analysis. Use the length of the list as the input size . Create a

For each method in the ArrayList class template, determine the asymptotic analysis. Use the length of the list as the input size For each method in the ArrayList class template, determine the asymptotic analysis..

Create a main.cpp file that tests each method of the ArrayList. Also create scenarios that cause the different error messages to appear.

  • List.hpp
  • ArrayList.hpp
  • main.cpp

#ifndef ARRAY_LIST_HPP #define ARRAY_LIST_HPP

#include "List.hpp" #include using namespace std;

// for all analyses // input size n is the length of the list

template class ArrayList : public List { private: // an array that contains the elements T* buffer;

// the maximum number of elements in the list int maxSize;

public: // constructor with the maximum size as the argument ArrayList(int = 100);

// copy constructor ArrayList(const ArrayList&);

// overloaded assignment operator ArrayList& operator=(const ArrayList&);

// destructor virtual ~ArrayList();

// add the argument to the end of the list virtual void append(const T&) override;

// remove all elements in the list virtual void clear() override;

// return the element at the given position (argument) virtual T getElement(int) const override;

// return the current length of the list virtual int getLength() const override;

// return the maximum size of the list int getMaxSize() const;

// insert the given element (argument 2) at // the given position (argument 1) virtual void insert(int, const T&) override;

// determine if the list currently empty virtual bool isEmpty() const override;

// determine if the list currently full bool isFull() const;

// remove the element at the given position (argument) virtual void remove(int) override;

// replace the element at the given position (argument 1) with // the value given (argument 2) virtual void replace(int, const T&) override;

// overloaded stream insertion operator template friend ostream& operator&); };

// analyzing number of assignments // T(n) = ? template ArrayList::ArrayList(int i) { this->length = 0; maxSize = i; buffer = new T[maxSize]; }

// analyzing number of assignments // T(n) = ? template ArrayList::ArrayList(const ArrayList& copyObj) { this->length = copyObj.length; maxSize = copyObj.maxSize; buffer = new T[maxSize];

for (int i = 0; i length; i++) { buffer[i] = copyObj.buffer[i]; } }

// analyzing number of assignments // T(n) = ? template ArrayList& ArrayList::operator=(const ArrayList& rightObj) { delete[] buffer;

this->length = rightObj.length; maxSize = rightObj.maxSize; buffer = new T[maxSize];

for (int i = 0; i length; i++) { buffer[i] = rightObj.buffer[i]; }

return *this; }

// analyzing number of deletes // T(n) = ? template ArrayList::~ArrayList() { delete[] buffer; }

// analyzing number of assignments // T(n) = ? template void ArrayList::append(const T& elem) { if (isFull()) { cout length] = elem; this->length++; } }

// analyzing number of assignments // T(n) = ? template void ArrayList::clear() { delete[] buffer; buffer = new T[maxSize]; this->length = 0; }

// analyzing number of accesses // T(n) = ? template T ArrayList::getElement(int position) const { return buffer[position]; }

// analyzing number of accesses // T(n) = ? template int ArrayList::getLength() const { return this->length; }

// analyzing number of accesses // T(n) = ? template int ArrayList::getMaxSize() const { return maxSize; }

// analyzing number of assignments // T(n) = ? template void ArrayList::insert(int position, const T& elem) { if (position = this->length) { cout length; i > position; i--) { buffer[i] = buffer[i - 1]; } buffer[position] = elem; this->length++; } }

// analyzing number of comparisons // T(n) = ? template bool ArrayList::isEmpty() const { return this->length == 0; }

// analyzing number of comparisons // T(n) = ? template bool ArrayList::isFull() const { return this->length == maxSize; }

// analyzing number of assignments // T(n) = ? template void ArrayList::remove(int position) { if (position = this->length) { cout length - 1; i++) { buffer[i] = buffer[i + 1]; } this->length--; } }

// analyzing number of assignments // T(n) = ? template void ArrayList::replace(int position, const T& elem) { if (position = this->length) { cout

// analyzing number of output operations // T(n) = ? template ostream& operator& myObj) { if (myObj.isEmpty()) { outStream

return outStream; }

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!