Lab 3: Array Lists

In this lab, you will complete 4 methods in the AList class: the copy constructor, addFirst, getFirst, and removeFirst.

1. Open lab folder in VSCode

Follow the instructions from Lab 1 to open the lab folder in VSCode.

The new files in this lab are

The remaining files/directories are similar to those in Lab 1. You are expected to modify AList.h to add your code for the 4 methods (search in the file for TODO) and upload it to the autograding system.

2. The copy constructor

The copy constructor in AList.h should deep-copy the other list, i.e., create a new list in which the elements are the same as in other.

3. Add/get/remove the first item in list

Method addFirst, getFirst and removeFirst should prepend the list, return the first item, and remove the first item in the list, respectively. You may assume the first/last item always exists.

For example, given a list L=[1,2,3,4]

🍩 Tips: You need to move elements in the underlying array backward and forward to remove and add an element in the front.

4. Build and test

A sample doctest test case is given in main.cpp. You can modify its content to create your own tests. But they will not be used for grading.

As in Lab 2, you need to run make clean test to run the provided doctest cases. If your code passed the test case, you would see the output like the following:

[doctest] doctest version is "2.4.8"
[doctest] run with "--help" for options
===============================================================================
[doctest] test cases: 1 | 1 passed | 0 failed | 0 skipped
[doctest] assertions: 6 | 6 passed | 0 failed |
[doctest] Status: SUCCESS!

5. Submitting the code

After testing the program locally, you should submit AList.h to the autograding system. There will be 10 test cases in total to evaluate your implementation. For each passing test case, you will get 3 points if there is no memory error and 2 points if there are memory errors.

You may refer to the instructions from Lab 1 for more instructions.