One way to implement the assignment operation is using the following steps:
- If original and I are two distinct lists (Note: this is different from inequality; think this and &):
- If I am not empty:
- Deallocate my chain of nodes.
- Set myFirst and myLast to NULL.
- Set mySize to zero.
- If original is not empty:
- Declare nPtr containing the address of original's first node .
- While nPtr is pointing at something:
- Append (to me) a copy of the item in the node to which nPtr is pointing.
- Advance nPtr to the next node.
- Return myself.