Question
C++ I need help implementing some methods to dynamically resize an array using templates. Here are the methods: You will need to create and ArrayList
C++
I need help implementing some methods to dynamically resize an array using templates.
Here are the methods:
You will need to create and ArrayList class that implements a dynamically resizable array using templates.
Here are the methods I am trying to implement:
//Default Constructor -- create a starting array with 10 slots/elements //Constructor (int size) -- create a starting array with given size //Copy constructor -- deep copy //Assignment operator -- deep copy //Destructor -- frees dynamically allocated memory
//set(int position, T value) sets the value at position //get(int position) gets the value at position //append(T value) appends the value to the end of the array -- extend the array if necessary //insert(int position, T value) inserts value at position -- moves everything else down one -- extend the array if necessary
Below you will find my .h file.
NOTE: I would appreciate comments that explain how the pointers (*) and ampersand (&) sign are working in these methods and how they all relate to eachother. I am having trouble understanding/grapsing this concept.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#ifndef ArrayList_hpp #define ArrayList_hpp #include
#define DEFAULT_SIZE 10
template
public: ArrayList(); //array list ArrayList(const ArrayList& other); ArrayList& operator=(const ArrayList& other); ~ArrayList(); void append(T value); //"append" adds value to the end of the array //grows the array as needed. void print(std::ostream& out) private: void copyList(T* old, int size); T* arr; int size; int capacity;
};
template
template
template
template
template
void ArrayList
#endif /* ArrayList_hpp */
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started