This lab is due by Tuesday, March 29, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.
Instructions
Make a copy of your ending point from Lab4D as we continue to modify and build out our class.
Class Expansion
We will continue refactoring our LinkedList class. There are three more public methods we will add to our class.
-
Name: Copy Constructor
Input: A LinkedList object
Output: nothing
Task: Perform a deep copy of the passed object. The newly constructed list will have the same size and ordered values as the passed list.
-
Name: Copy Assignment Operator
Input: A LinkedList object
Output: Reference to a LinkedList object
Task: Deallocate the current list. Perform a deep copy of the passed object. The new list will have the same size and ordered values as the passed list.
-
Name:
at
Input: An integer position
Output: integer
Task: The value at the provided position. -1 if out of range.
Class Testing
Now in main.cpp
, perform the following steps to verify the class is working correctly:
- Create a LinkedList object using the default constructor
- Print out its initial size (should be zero)
- Add the following values to the list in order:
- Push front 1
- Push back 2
- Push front 3
- Push back 4
- Push front 5
- Push back 6
- Print out the new size (should be six)
- Print out the contents of the list (should be 5 3 1 2 4 6)
- Create a second LinkedList object using the default constructor
- Print out its initial size (should be zero)
- Assign the first LinkedList to the second LinkedList
- Print out both their sizes (both should be six)
- Add the following values to the first list in order:
- Push front 7
- Push back 8
- Print out both their sizes and contents (first should be 8 elements of 7 5 3 1 2 4 6 8, second should be 6 elements of 5 3 1 2 4 6)
- Create a third LinkedList using the copy constructor and providing the first LinkedList as an argument
- Print out all three sizes (should be eight, six, eight)
- Add the following values to the first list in order:
- Push front 9
- Push back 10
- Print out all three sizes (should be ten, six, eight)
- Print out the contents of all three lists (should be first - 9 7 5 3 1 2 4 6 8 10, second - 5 3 1 2 4 6, third - 7 5 3 1 2 4 6 8)
- Delete all three lists to clean up all memory
Be sure to save a snapshot of your code at this point. We will make a copy to start Lab4F as we continue to modify, build out, and test our class.
Lab Submission
Submit your Node.h, LinkedList.h, LinkedList.cpp, main.cpp
file(s).
You will submit your solution to this lab with the rest of Set4. Detailed instructions for doing this are posted in Assignment 4.
This lab is due by Tuesday, March 29, 2022, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.