Question: I am attempting to remove a node with a passed in value from a circular linked list recursively. All data is private so recursive helpper
I am attempting to remove a node with a passed in value from a circular linked list recursively. All data is private so recursive helpper function needed. What's wrong with my code? some functions omitted for simplicity
int main
CircularLinkedList myList;
myList.insertAtEnd;
myList.insertAtEnd;
myList.insertAtEnd;
std::cout "Original list: std::endl;
myList.display;
myList.deleteNode;
std::cout "List after deleting node with value : ;
myList.display;
return ;
Node CircularLinkedList::deleteNodeRecursiveNode current, int value
if current nullptr
return nullptr;
if currentgetData value
Node temp currentgetNext;
Check if node to be deleted is the head of the list
if current head
Update head to the next node
head temp;
If the list becomes empty
delete current;
return temp;
Set the next pointer of the current node to the result of the recursive call
currentsetNextdeleteNodeRecursivecurrentgetNext value;
Same as above but in steps:
Node nextNode currentgetNext; Step
Node updatedNextNode deleteNodeRecursivenextNode value; Step
currentsetNextupdatedNextNode; Step
return current;
void CircularLinkedList::deleteNodeint value
if head nullptr
head deleteNodeRecursivehead value;
if head nullptr
std::cout "Value value not found in the list." std::endl;
else
std::cout "Node with value value deleted." std::endl;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
