Courses/CS 2124/Lab Manual/Elastic Array Part 2

From A-State Computer Science Wiki
Jump to: navigation, search

An “Elastic” Array — Part 2

In a previous lab, you created an ElasticArray class that allows an array of any size to be created at runtime. The class used the concept of RAII by utilizing a destructor to ensure that the dynamically-allocated internal storage array was properly deleted when it left memory. Your ElasticArray had the following properties:

  • ElasticArray is default-constructable.
  • ElasticArray is copy-constructable.
  • ElasticArray is copy-assignable and will exhibit correct “by-value” semantics.
  • ElasticArray implements:
    • front() method that will allow the items at the front of the array to be accessed.
    • back() method that will allow the items at the back of the array to be accessed.

In this exercise, you will extend your ElasticArray class definition to allow it to grow or shrink on demand (much like std::vector), and then explore how iterators are designed by wrapping an observing pointer to the ElasticArray’s internal storage.