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 Lab4C as we continue to modify and build out our class.
Class Declaration
We will begin refactoring our LinkedList class. First, denote separate public and private sections of our class.
Our data members and the makeNodeForValue()
method will all be private. Be sure to follow our
naming scheme style. The remainder of the existing methods will be public.
We no longer have direct access to our data members, so we will add some public accessors for them. Think about why we won't be having public mutators for the data members. Create the following public methods:
-
Name: front
Input: none
Output: an integer
-
Name: back
Input: none
Output: an integer
-
Name: size
Input: none
Output: an unsigned integer
Lastly, declare a constructor and destructor for the class.
Class Definition
In a separate LinkedList.cpp
file, we'll now make the implementations for each method. Below are the
tasks each method should be performing:
-
Constructor
: Sets the head & tail pointers to be null. Sets the size to be zero. -
Destructor
: Deletes all nodes in the list. Updates the head & tail pointers and size as appropriate. -
mMakeNodeForValue()
: Returns a node pointer to a newly made node whose value is set to the parameter passed in and the next pointer is set to be null. -
pushFront()
: Adds a node to the head of the list with the provided parameter value. Updates the head & tail pointers and size as appropriate. -
pushBack()
: Adds a node to the tail of the list with the provided parameter value. Updates the head & tail pointers and size as appropriate. -
popFront()
: Deletes the node at the head of the list and returns its value. Updates the head & tail pointers and size as appropriate. If list is empty, returns -1 by default. -
front()
: Returns the current value of the head node. If list is empty, returns -1 by default. -
back()
: Returns the current value of the back node. If list is empty, returns -1 by default. -
size()
: Returns the current size.
Be sure to save a snapshot of your code at this point. We will make a copy to start Lab4E as we continue to modify, build out, and test our class.
Lab Submission
Submit your Node.h, LinkedList.h, LinkedList.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.