Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the following in C++ using the given template below #include using namespace std; template class ArrayList { public: ArrayList(size_t asize=10) { // To do

Implement the following in C++ using the given template below

image text in transcribed

#include

using namespace std;

template class ArrayList { public: ArrayList(size_t asize=10) { // To do }

~ArrayList() { // To do }

ArrayList(const ArrayList &other) { // To do }

ArrayList& operator= (const ArrayList &other) { // To do return *this; }

void insertAt(Item a, size_t index=0) { // To do } Item& at(size_t index) { // To do } void remove(size_t index) { // To do } bool empty() { // To do return true; } size_t find(Item item) { return 0; } size_t size() { // To do } };

// DO NOT MODIFY BELOW HERE template ostream& operator &array) { out

int main() { ArrayList l; for (int i=0; i l2 = l; cout Implement an ArrayList as a templatized class where the item held in the array is of the specialized type: template class ArrayList { }; The ArrayList will use an array type as the underlying data structure of the List. When items are inserted at the beginning or middle, the other content in the array needs to be moved around to compensate. Provide at least the following public functions: insertAt(Item, index=0): insert item at index, default position is 0; shift existing item at the same index and above to higher indices to compensate. index must be between 0 and size() inclusive. Inserting at size() means to put it at the end. at(index): get item at index; remove(index): remove item at index; shift all other items at greater indices down one. empty(): whether array is empty or not. find(Item): return first index of matching item. If not found, return value >= size size(): return number of items in the list; valid indices for at() must run from 0 to size()-1. When inserting, inserting at the tail can be achieved by inserting at size(). Note, if your array is insufficient in size, you need to allocate a bigger array on the fly. You may decide the best way to manage that process. Your class should follow the rule of three, and provide a copy constructor, assignment operator, and destructor. The copy constructor and assignment operator should implement a deep copy. You should also offer a default constructor that takes the initial size of the underlying array as an argument

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions