Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions

Question

Consider this article:...

Answered: 1 week ago