Develop a linked-list processing function, IsolateTargetSoloAsTail, to process a linked list as follows.
● |
If a target cannot be found on the given list, a new node containing the target is created and added to the list's end (made the new tail node). |
|
|
► |
This includes the case where the given list is empty, in which the new tail node added is also the new head node. (This is so because the only node in a 1-node list is the list's head and tail node.) |
|
● |
If the target appears only once on the given list, the target-matching node is moved to the list's end (made the new tail node). |
|
|
► |
Nothing needs to be done if the target-matching node is already the tail node (of the given list). |
|
● |
If the target appears multiple times on the given list, the first target-matching node is moved to the list's end (made the new tail node), and all other target-matching nodes are to be deleted from the list. |
|
|
► |
Note that although the target-matching node to be moved does not have to be the first (i.e., it can also be any of the other target-matching nodes) for the function to work as intended, you are to make it so for the purpose (and simplicity/uniformity) of this exercise. |
|
|
|
○ |
NOT change the data of any existing nodes. |
|
|
|
○ |
Destroy ONLY existing nodes that constitute the second target-matching node, third target-matching node, etc. |
evelop a linked-list processing function IsolateTargetSoloAsTail that is to process a linked list as follows.
● |
If target cannot be found on the given list, a new node containing target is created and added to the end (made the new tail node) of the list. |
|
|
► |
This includes the case where the given list is empty, in which case the new tail node added is also new head node. (This is so because the only node in a 1-node list is both the head and tail node of the list.) |
|
● |
If target appears only once on the given list, the target-matching node is moved to the end (made the new tail node) of the list. |
|
|
► |
In case the target-matching node is already the tail node (of the given list), then nothing needs to be done. |
|
● |
If target appears multiple times on the given list, the first target-matching node is moved to the end (made the new tail node) of the list, and all other target-matching nodes are to be deleted from the list. |
|
|
► |
Note that although the target-matching node to be moved does not have to be the first (i.e., it can also be any of the other target-matching nodes) for the function to work as intended, you are to make it so for the purpose (and simplicity/uniformity) of this exercise. |
void IsolateTargetSoloAsTail(Node* headPtr, int target);