Building the Linked List
The Constructor
This is easy
Set the size to be 0
Set the head pointer to be nullptr.
The destructor
What is this function responsible for?
Any class with dynamic memory
MUST
have a destructor to free that memory.
When will it be called?
What should it do?
For each node in the list delete the node
Insert
There are two cases here
The new node goes at the front of the list
The new node goes somewhere in the list.
How will we know when each occurs?
The first case is trivial.
For problems like the second case, I like to use a two pointer solution
NodeT * seek, * tail
seek
points to the node where the insert will occur
tail
points to one behind that.
Move
seek
along until
It points to nullptr (insert at the end of the list)
It points to a data value greater than what is to be inserted.
Follow one behind with
tail
When you are finished, this will be where to insert.
Delete is much like insert.
But you might not find anything to delete.
The others are no problem.
Please see
ListT.cpp
Look this over.
You need to understand this.