Linked Lists C++ Flashcards

(7 cards)

1
Q

Insertion algorithm

A

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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Removal algorithim

A

//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;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Array / Node indexing

A

Use a for loop that increments exactly n times from the head.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Assignment / copy constructor

A

While pCurr != nullptr, append value at pCurr and incriment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Construct from array

A

Loop size times and append

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Append

A

//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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Prepend

A

SLList::nodeItem* pHeadNodeAllocation{new SLList::nodeItem{val, mPFirst}};

//Update last ellement if needed
if(mPLast == nullptr) {
mPLast = pHeadNodeAllocation;
}

//Always update first ellement
mPFirst = pHeadNodeAllocation;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly