You did not show the definition of your linkedList.
So I can only suppose that it has data members ptrTail and ptrHead. In this case the function will look the following way
void linkedList::addBack(int addData)
{
node* n = new node; //create new node
n->data = addData; //input data
n->next = NULL; //set node to point to NULL
if ( ptrTail == NULL ) // or if ( ptrTail == nullptr )
{
ptrHead = n;
}
else
{
ptrTail->next = n;
}
ptrTail = n;
size++;
}
Function addFront
can be defined the similar way
void linkedList::addFront(int addData)
{
node* n = new node; //create new node
n->data = addData; //input data
if ( ptrHead == NULL ) // or if ( ptrHead == nullptr )
{
ptrTail = n;
}
n->next = ptrHead;
ptrHead = n;
size++;
}
One more function
void linkedList::removeFront()
{
if ( ptrHead != NULL )
{
if ( ptrTail == ptrHead ) ptrTail = NULL;
node* n = ptrHead;
ptrHead = ptrHead->next;
delete n;
size--;
}
}