Code:
StringList()
{
head = NULL;
}
...
//Constructor definition
StringList::StringList()
{
head = nullptr;
}
You are defining the body of the default constructor in both the .h and .cpp files??
Code:
StringList::~StringList()
{
delete head;
clear();
}
No. Assuming that clear() removes the entries from the list, it would also delete head. Also, clear() needs to use the value from head to traverse the list to remove the nodes. delete head should be the last thing done, not the first. Have you got the code for clear()?
Quote:
StringList is a modified version of NumberList class
Have got the code for NumberList? Changing from storing a number to storing a string is quite trivial.
Code:
nodePtr = head;
cout << "Here is the list: \n\t";
while (nodePtr)
{
cout << nodePtr -> a << " -> ";
}
nodePtr = nodePtr -> next;
Note that this would usually be coded as
Code:
for (auto nodePtr = head; nodePtr; nodePtr = nodePtr->next)
cout << nodePtr -> a << " -> ";
Quote:
Define deleteBack function
This requires the list to be traversed and then the last node deleted. The next pointer from the node prior to the one deleted is then set to nullptr.
Quote:
Define insertFront function
Insert a new node at the front of the list. This needs head to be adjusted accordingly.
Quote:
Define insertBack function
Insert a new node at the end of the list. This needs the list to be traversed to the end and then a new node added to the end with the next pointer of the was last node set to point to the the new last node.
Quote:
this I'm extremely confused about....someone can guide in the right direction
If you are still having problems, you'll need to be more specific about the issues you are having. This exercise is just a simple single linked list.