In this lab, you will complete 4 methods in the AList
class: the copy constructor, addFirst
, getFirst
, and removeFirst
.
Follow the instructions from Lab 1 to open the lab folder in VSCode.
The new files in this lab are
AList.h
: the definition of the AList
classThe 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.
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
.
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]
L.getFirst()
will return the first element in L
which is 1
;L.addFirst(5)
will insert 5
as the first element and result in L=[5,1,2,3,4]
;L.removeFirst()
will delete and return 1
in L
.🍩 Tips: You need to move elements in the underlying array backward and forward to remove and add an element in the front.
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!
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.