This lab is due by Friday, July 15, 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
We will begin refactoring our LinkedList operations from a structured procedural style to a more Object-Oriented approach.
Start by copying the Node.h
header from Lab3B and
placing it in this folder. Now create a new file called LinkedList.h
that will store our Linked List class
declaration. Note the naming scheme of our files now. We're using the PascalCase (UpperCamelCase) to denote this
file contains a class declaration (since it's a header) and the name of the class is LinkedList.
The Class Shell
Begin by creating the LinkedList class declaration. This class will represent a LinkedList data structure. It's contained state will be the actual linked list and it will contain the methods to manipulate that state - the linked list.
The UML for the class is described below (with a description of the corresponding use):
Linkedlist
- Data Members
- -
mpHead
:Node*
pointer to the head node of the list - -
mpTail
:Node*
pointer to the tail node of the list - -
mSize
:unsigned int
stores the current number of nodes in the list
- -
- Member Functions
- +
LinkedList()
creates an empty list that has no size and a null head & tail - +
at(const int POS)
:int
returns the value of the element at given position. If position doesn't exist, returns -1 - +
find(const int TARGET)
:int
returns the position of the first occurrence of the target. If target doesn't exist, returns -1 - +
insert(const int POS, const int VALUE)
:void
inserts a new node with the provided value BEFORE the provided position. That is, the newly created node will point to the current node at the provided position. If the provided position is out of range for the current list, then cap the position to the head or tail of the list as appropriate - +
max()
: int
returns the max value within the list. If the list is empty, returns -1 - +
min()
: int
returns the min value within the list. If the list is empty, returns -1 - +
remove(const int POS)
:void
if the provided position exists in the list, removes and deallocates the associated node - +
set(const int POS, const int VALUE)
:void
if the provided position exists in the list, sets the vale of the associated node - +
size()
:unsigned int
returns the current number of nodes within the list - -
mMakeNodeForValue(const int VALUE)
:Node*
creates a node with provided value and null next pointer
- +
- Data Members
Again, a test suite has been provided in linked_list_class_tests.zip. This time, the test suite will not compile until the class is declared and the functions are stubbed out.
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 Friday, July 15, 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.