Implement the operations below. Use assert to check preconditions. Note: ValueTy
ID: 3592634 • Letter: I
Question
Implement the operations below. Use assert to check preconditions. Note: ValueType below is intended to be the template type parameter used when this class is dened. Also, each of these must be template methods with ValueType as the template parameter.
- sequence() –construct an empty sequence. Set the size, the initial capacity(to1or more)and allocate the array
- std :: size_t size() const – return the number of items stored in the sequence.
- ValueType& at(std :: size_t i) – (precondition: i < size()) return the item at position i in the sequence. Note that sequence indices start at zero (just like arrays).
- ValueType&operator[](std:: size_t i) – return the item at position i in the sequence (without bounds check). Note that sequence indices start at zero (just like arrays).
- bool empty() const – return true if this sequence is empty, false otherwise.
- void add(const ValueType& value) – add the specied value to the end of the sequence.
- void insert (std :: size t index, const ValueType& value) – (precondition: index <= size()) insert the specied value at the specied index, shifting values to higher indexes if needed. If index == size this operation is the same as add.
- void remove(std:: size t index) – (precondition: index < size()) remove the value at the specied index, shifting other values down as needed.
- the “big 5” – implement the copy constructor, move constructor, copy assignment operator, move assignment operator, and destructor
- sequence operator +(const sequence& s1, const sequence& s2) – free function (you may implement this as a member function if you prefer) return a new sequence that is the result of appending s2 onto the end of s1.
- void operator +=(const sequence& other) – append other onto the end of this sequence.
Instance variables
You will need the following instance variables (ValueType below is intended to be the template type parameter used when this class is dened):
1- ValueTypeitems – the (dynamically sized) array where we store the items in the list.
2- std:: size t used – the number of items being used in the array.
3- std:: size t capacity – the number of elements allocated for the array