Insertion algorithm
Always do prepend or append first, the algorithm core is then:
//Create the new ellement, pointing to the right node (node after)
SLList::nodeItem* newNodeItem{new SLList::nodeItem{val, ellementAfter}};
//Update ellement before to point to the next ellement
(*ellementBefore).mNodeNextNode = newNodeItem;
Removal algorithim
//Update ellement before to ellement after
if(!isHeadUpdating && !isTailUpdating) {
(ellementBefore).mNodeNextNode = ellementAfter;
} else if(!isHeadUpdating && isTailUpdating){
(ellementBefore).mNodeNextNode = nullptr;
mPLast = ellementBefore;
} else if(isHeadUpdating && !isTailUpdating) {
mPFirst = ellementAfter;
} else if (isHeadUpdating && isTailUpdating) {
mPLast = nullptr;
mPFirst = nullptr;
}
Array / Node indexing
Use a for loop that increments exactly n times from the head.
Assignment / copy constructor
While pCurr != nullptr, append value at pCurr and incriment.
Construct from array
Loop size times and append
Append
//If this is the new first ellement in the list, update the head pointer
if(mPFirst == nullptr) {
mPFirst = pHeadNodeAllocation;
}
//If the list has data, update the ellement pointed to by tail to point to this value
else {
(*mPLast).mNodeNextNode = pHeadNodeAllocation;
}
//No matter what, update the tail to point to the new data
mPLast = pHeadNodeAllocation;
Prepend
SLList::nodeItem* pHeadNodeAllocation{new SLList::nodeItem{val, mPFirst}};
//Update last ellement if needed
if(mPLast == nullptr) {
mPLast = pHeadNodeAllocation;
}
//Always update first ellement
mPFirst = pHeadNodeAllocation;