Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me get the errors clean out of my code CODE: / / * * * * * * * * * * *

Please help me get the errors clean out of my code CODE: //******************
//The Node class
//******************
template
class Node {
public:
T data{};
Node* link{ nullptr };
};
//******************
// The linked list base class
//******************
template
class LinkedListBase {
public:
~LinkedListBase();
T getFifthElement() const { cerr "Error: You didn't override this base class method yet" endl; T temp{}; return temp; }
void insertNewFifthElement(const T& data){ cerr "Error: You didn't override this base class method yet" endl; }
void deleteFifthElement(){ cerr "Error: You didn't override this base class method yet" endl; }
void swapFifthAndSeventhNodes(){ cerr "Error: You didn't override this base class method yet" endl; }
T getLast() const;
void pushFront(const T& data);
void pushBack(const T& data);
void popFront();
void popBack();
string getStringFromList();
protected:
Node* head{ nullptr };
Node* tail{ nullptr };
unsigned int count{0};
}; //**********************************
//Write your code below here
//**********************************
template
class SinglyLinkedList : public LinkedListBase {
public:
// TODO, your methods declarations here
T getFifthElement() const;
void insertNewFifthElement(const T& value);
void deleteFifthElement();
void swapFifthAndSeventhNodes();
};
// TODO, your method definitions here
template
T getFifthElement()
{
if (this->count 5){
throw std::runtime_error("Not enough elements in the list.");
}
if (this->count ==5)
{
return data{};
}
};
template
void insertNewFifthElement(const T& value)
{
if (this->count 4)
{
this->insert(value);
} else
{
ewNode->data = value;
fourthNode = this->front;
for (int i =0; i 3; ++i)
{
fourthNode = fourthNode->next;
}
newNode->next = fourthNode->next;
fourthNode->next = newNode;
++this->count;
}
};
template
void deleteFifthElement()
{
if (this->count 5)
{
throw std::runtime_error("Not enough elements in the list.");
}
fourthNode = this->front;
for (int i =0; i 3; ++i)
{
fourthNode = fourthNode->next;
}
fifthNode = fourthNode->next;
fourthNode->next = fifthNode->next;
if (fifthNode == this->back)
{
this->back = fourthNode;
}
--this->count;
};
template
void swapFifthAndSeventhNodes()
{
if (this->count 7){
throw std::runtime_error("Not enough elements in the list.");
}
fifthNode = temp1;
seventhNode = temp2;
temp1= seventhNode;
temp2= fifthNode;
};
//**********************************
//Write your code above here
//**********************************
image text in transcribed

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

Step: 3

blur-text-image

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

Advances In Databases 11th British National Conference On Databases Bncod 11 Keele Uk July 7 9 1993 Proceedings Lncs 696

Authors: Michael F. Worboys ,Anna F. Grundy

1993rd Edition

3540569219, 978-3540569213

More Books

Students also viewed these Databases questions

Question

________ is the total of an employees pay and benefits.

Answered: 1 week ago