Adding to (either) end of a list is very common, but compar the amount of work required:
template <typename Data>
void LListHeader<Data>::addToFront (const Data& value)
{
LListNode<Data>* newNode = new LListNode<Data>(value, first);
first = newNode;
}
template <typename Data>
void LListHeader<Data>::addToEnd (const Data& value)
{
LListNode<Data>* newNode = new LListNode<Data>(value, NULL);
if (first == NULL)
{
first = newNode;
}
else
{
// Move to last node
LListNode<Data>* current = first;
while (current->next != NULL)
current = current->next;
// Link after that node
current->next = newNode;
}
}
