CSCI 261 - Programming Concepts - Spring 2022

Lab 4E - A Linked List Class Part III: Test, Copy, Print

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.

  1. 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.

  2. 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.

  3. 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:

  1. Create a LinkedList object using the default constructor
  2. Print out its initial size (should be zero)
  3. Add the following values to the list in order:
    1. Push front 1
    2. Push back 2
    3. Push front 3
    4. Push back 4
    5. Push front 5
    6. Push back 6
  4. Print out the new size (should be six)
  5. Print out the contents of the list (should be 5 3 1 2 4 6)
  6. Create a second LinkedList object using the default constructor
  7. Print out its initial size (should be zero)
  8. Assign the first LinkedList to the second LinkedList
  9. Print out both their sizes (both should be six)
  10. Add the following values to the first list in order:
    1. Push front 7
    2. Push back 8
  11. 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)
  12. Create a third LinkedList using the copy constructor and providing the first LinkedList as an argument
  13. Print out all three sizes (should be eight, six, eight)
  14. Add the following values to the first list in order:
    1. Push front 9
    2. Push back 10
  15. Print out all three sizes (should be ten, six, eight)
  16. 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)
  17. 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.