Question: / / main . cpp #include SinglyLinkedList.h #include #include #include using namespace std; void listRemoveAfter ( LinkedList * list, Node * curNode ) {
maincpp
#include "SinglyLinkedList.h
#include
#include
#include
using namespace std;
void listRemoveAfterLinkedList list, Node curNode
if list nullptr listhead nullptr
The list is empty or curNode is nullptr head nothing to remove.
return;
if curNode nullptr
If curNode is nullptr, remove the head node.
Node temp listhead;
listhead listheadnext;
if listhead nullptr
If the list becomes empty, update the tail as well.
listtail nullptr;
delete temp;
else
Remove the node after curNode.
Node temp curNodenext;
if temp nullptr
curNodenext tempnext;
if temp listtail
If the removed node was the tail, update the tail.
listtail curNode;
delete temp;
string listDescriptorLinkedList list
if list nullptr listhead nullptr
return ;
ostringstream oss;
Node current listhead;
while current nullptr
oss currentperson.descriptor endl;
current currentnext;
return oss.str;
int main
LinkedList list;
Add nodes to the list
Person person "John", "Doe";
Person person "Jane", "Doe";
Person person "Mary", "Doe";
Person person "Paul", "Doe";
list.head new Nodeperson;
list.headnext new Nodeperson;
list.headnextnext new Nodeperson;
list.headnextnextnext new Nodeperson;
list.tail list.headnextnextnext;
Test listRemoveAfter
listRemoveAfter&list, nullptr; removes head
listRemoveAfter&list, list.headnext; removes tail
Print the updated list
cout listDescriptor&list endl;
return ;
singlelinkedlisth
#ifndef SINGLYLINKEDLIST
#define SINGLYLINKEDLIST
#include
using namespace std;
class: Node
class Node
public:
Person person;
Node next;
Nodeconst Person& p : personp nextnullptr
;
class: LinkedList
class LinkedList
public:
Node head;
Node tail;
LinkedList : headnullptr tailnullptr
;
#endif
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
