Question: How can I replace a node in a (custom) Singly LinkedList with a (custom) Singly LinkedList? Note: The exact below CustomLinkedList Class below must be
How can I replace a node in a (custom) Singly LinkedList with a (custom) Singly LinkedList?
Note: The exact below CustomLinkedList Class below must be used to complete this.
Let's say that the CustomLinkedList listVar has the enumName_t data in it like SOUTH -> EAST -> WEST -> NORTH -> DOWN and we want to replace the node at the NORTH data with CustomLinkedList replacerList that has the enumName_t data in it WEST->SOUTH->EAST->DOWN->WEST such that the result node will look like the following:
SOUTH -> EAST -> WEST -> WEST->( SOUTH->EAST->DOWN->WEST )-> DOWN
SOUTH -> EAST -> WEST -> WEST-> SOUTH->EAST->DOWN->WEST -> DOWN (without parenthesis)
The information needed about CustomLinkedList can be found below and must be used to implement the above mechanics.
enum enumName_t { NORTH, SOUTH, EAST, WEST, DOWN };
class CustomLinkedList
{
typedef struct node
{
enumName_t data;
struct node* next;
void operator=(const struct node& rhs)
{ move = rhs.move; }
} node_t;
private:
node_t* head;
node_t* tail;
double duration;
public:
class iterator
{
private:
const node_t* node;
public:
iterator(const node_t* node) : node(node) {}
enumName_t operator*() const { return node->data; }
void operator++() { node = node->next; }
bool operator!=(iterator rhs) const { return node != rhs.node; }
};
InstructionList()
{ head = tail = nullptr; duration= 1.0; }
~InstructionList();
iterator begin() const { return iterator(head); }
iterator end() const { return iterator(nullptr); }
iterator end() const { return iterator(nullptr); }
};
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
