Question: / / Main . cpp #include SinglyLinkedList.h #include #include #include using namespace std; int main ( ) { LinkedList list; list.append ( new Person
Maincpp
#include "SinglyLinkedList.h
#include
#include
#include
using namespace std;
int main
LinkedList list;
list.appendnew Person "John", "Doe";
list.appendnew Person "Jane", "Doe";
list.appendnew Person "Paul", "Harvey";
Node searchResult listSearch&list, ;
if searchResult
cout "listSearch found: searchResultpersondescriptor endl;
else
cout "listSearch did not find the key." endl;
string descriptor listDescriptor&list;
cout "listDescriptor output:
descriptor;
Node current list.head;
while current
Node next currentnext;
delete currentperson;
delete current;
current next;
return ;
singleylinkedlisth
#ifndef SINGLYLINKEDLIST
#define SINGLYLINKEDLIST
using namespace std;
class Node
public:
Person person; Pointer to a Person instance
Node next; Pointer to the next Node instance
NodePerson p nullptr : personp nextnullptr
;
class LinkedList
public:
Node head; Pointer to the head of the linked list
Node tail; Pointer to the tail of the linked list
LinkedList : headnullptr tailnullptr
void appendPerson p
Node newNode new Nodep;
if head
head newNode;
tail newNode;
else
tailnext newNode;
tail newNode;
;
Node listSearchLinkedList list, const int key
Node current listhead;
while current
if currentpersonid key
return current;
current currentnext;
return nullptr; Key not found
string listDescriptorLinkedList list
ostringstream oss;
Node current listhead;
while current
oss currentpersondescriptor endl;
current currentnext;
return oss.str;
#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
