Question: I need help with my list 3 4 2 . h . It doesn't compile the expected output: class 1 : PradnyaDhala 8 AngieHam 7

I need help with my list342.h. It doesn't compile the expected output: "class1: PradnyaDhala8AngieHam7CesarRuiz6PiqiTangi7BillVollmann13RussellWilson13
ERROR::: Duplicate
Class2: HankAaron3CesarRuiz6PiqiTangi7RussellWilson13JohnZorn4
class1 and 2 Merged:
HankAaron3PradnyaDhala8AngieHam7CesarRuiz6PiqiTangi7BillVollmann13RussellWilson13JohnZorn4
Removed from class1, student AngieHam7
class1: HankAaron3PradnyaDhala8BillVollmann13RussellWilson13JohnZorn4
soccer: MilesDavis65CesarRuiz6RussellWilson13
soccer += class1 :
HankAaron3MilesDavis65PradnyaDhala8CesarRuiz6BillVollmann13RussellWilson13JohnZorn4
football: HankAaron3MilesDavis65PradnyaDhala8CesarRuiz6BillVollmann13RussellWilson13JohnZorn4
RussellWilson13 is on the football team
These are the numbers: -1113" here's my code: #ifndef LIST342_H
#define LIST342_H
#include
#include
#include
#include
#include "child.h"
template
struct Node {
T* data;
Node* next;
};
template
class List342{
public:
List342();
List342(const List342& source);
~List342();
bool BuildList(std::string file_name);
bool Insert(T* obj);
bool Remove(T target, T& result);
bool Peek(T target, T& result) const;
int Size() const;
void DeleteList();
bool Merge(List342& list1);
List342& operator=(const List342& source);
List342 operator+(const List342& rhs) const;
List342& operator+=(const List342& rhs);
bool operator==(const List342& rhs) const;
bool operator!=(const List342& rhs) const;
template
friend std::ostream& operator<<(std::ostream& os, const List342& list);
private:
Node* head;
void CopyList(const List342& source);
void RecursiveDelete(Node* current);
void RecursiveMerge(Node*& dest, Node*& source);
};
template
List342::List342() : head(nullptr){}
template
List342::List342(const List342& source) : head(nullptr){
CopyList(source);
}
template
List342::~List342(){
DeleteList();
}
// Member functions
template
bool List342::BuildList(std::string file_name){
std::ifstream file(file_name);
if (!file.is_open()){
return false; // Failed to open file
}
T obj;
while (file >> obj){
Insert(new T(obj));
}
file.close();
return true;
}
template
bool List342::Insert(T* obj){
Node* current = head;
if (!obj){
return false;
}
while (current){
if (*obj ==*current->data){
return false; // Duplicate item
}
current = current->next;
}
Node* newNode = new Node();
if (!newNode){
return false; // Memory allocation failed
}
newNode->data = new T(*obj); // Copy the object
newNode->next = nullptr;
current = head;
Node* prev = nullptr;
while (current && *current->data <*newNode->data){
prev = current;
current = current->next;
}
if (prev){
prev->next = newNode;
} else {
head = newNode;
}
newNode->next = current;
return true;
}
template
bool List342::Remove(T target, T& result){
Node* current = head;
Node* prev = nullptr;
while (current && *current->data != target){
prev = current;
current = current->next;
}
if (!current){
return false; // Target not found
}
if (prev){
prev->next = current->next;
} else {
head = current->next;
}
result =*(current->data);
delete current->data;
delete current;
return true;
}
template
bool List342::Peek(T target, T& result) const {
Node* current = head;
while (current && *current->data != target){
current = current->next;
}
if (!current){
return false; // Target not found
}
result =*(current->data);
return true;
}
template
int List342::Size() const {
int count =0;
Node* current = head;
while (current){
count++;
current = current->next;
}
return count;
}
template
void List342::DeleteList(){
RecursiveDelete(head);
head = nullptr;
}
template
bool List342::Merge(List342& list1){
RecursiveMerge(head, list1.head);
list1.DeleteList(); // Empty the merged list
return true;
}
// Overloaded operators
template
List342& List342::operator=(const List342& source){
if (this != &source){
DeleteList();
CopyList(source);
}
return *this;
}
template
List342 List342::operator+(const List342& rhs) const {
List342 result =*this;
result += rhs;
return result;
}
template
List342& List342::operator+=(const List342& rhs){
Node* current = rhs.head;
while (current){
T result;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!