Question: Hi, I'm doing this code project and I need help with my code. I am getting this error and I don't know how to fix

Hi, I'm doing this code project and I need help with my code. I am getting this error and I don't know how to fix it.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

INSTRUCTIONS

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Hi, I'm doing this code project and I need help with my

-MAIN.CPP-

code. I am getting this error and I don't know how to

fix it. ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- INSTRUCTIONS ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -MAIN.CPP- -LEAKER.H- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- MY CODE AND THE

ERROR I'M GETTING ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #ifndef LINKEDLIST_H #define LINKEDLIST_H #include template class LinkedList

{ public: class Node { public: T data; Node *next; Node *prev;

Node(T data) : data(data), next(nullptr), prev(nullptr){}; }; public: // This section describes

-LEAKER.H-

the methods that are accessible for the LinkedList // class LinkedList(); void AddTail(T data); void AddHead(T data); void PrintForward(); Node *Find(T searchData); void InsertBefore(Node *, T data); void InsertAfter(Node *, T data); void InsertAt(T data, intposition); int NodeCount() const; ~LinkedList(); private: Node *head; Node *tail; int totalNodes; }; template LinkedList::LinkedList() : head(nullptr), tail(nullptr), totalNodes(0){} template void LinkedList::AddTail(T data) {Node *newNode = new Node(data); if (tail == nullptr && head ==

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

MY CODE AND THE ERROR I'M GETTING

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#ifndef LINKEDLIST_H #define LINKEDLIST_H

#include

template class LinkedList { public: class Node { public: T data; Node *next; Node *prev; Node(T data) : data(data), next(nullptr), prev(nullptr){}; };

public: // This section describes the methods that are accessible for the LinkedList // class LinkedList(); void AddTail(T data); void AddHead(T data); void PrintForward(); Node *Find(T searchData); void InsertBefore(Node *, T data); void InsertAfter(Node *, T data); void InsertAt(T data, int position); int NodeCount() const; ~LinkedList();

private: Node *head; Node *tail; int totalNodes; };

template LinkedList::LinkedList() : head(nullptr), tail(nullptr), totalNodes(0){}

template void LinkedList::AddTail(T data) { Node *newNode = new Node(data); if (tail == nullptr && head == nullptr) { head = newNode; tail = newNode; } else { tail->next = newNode; newNode->prev = tail; tail = newNode; } totalNodes++; }

template void LinkedList::AddHead(T data) { Node *newNode = new Node(data); if (tail == nullptr && head == nullptr) { head = newNode; tail = newNode; } else { newNode->next = head; head->prev = newNode; head = newNode; } totalNodes++; }

template void LinkedList::InsertAfter(LinkedList::Node *currentNode, T data) { Node *newNode = new Node(data); Node *nextNode = currentNode->next;

// connecting links to the newNode currentNode->next = newNode;

// checking if the nextNode is not null // if not null then set the prev of the nextNode to the newNode if (nextNode != nullptr) { nextNode->prev = newNode; }

// connecting the newNode links newNode->prev = currentNode; newNode->next = nextNode;

// checking if the newNode is the last node of not if (newNode->next == nullptr) { // if the newNode is the lastNode, then set tail to newNode tail = newNode; }

totalNodes++; }

template void LinkedList::InsertBefore(LinkedList::Node *currentNode, T data) { Node *newNode = new Node(data); Node *prevNode = currentNode->prev;

currentNode->prev = newNode;

if (prevNode != nullptr) { prevNode->next = newNode; }

// connecting the newNode links newNode->next = currentNode; newNode->prev = prevNode;

// if the newNode is the first node, then set it to head if (newNode->prev == nullptr) { head = newNode; }

totalNodes++; }

template void LinkedList::InsertAt(T data, int position) { if (position == 0) { AddHead(data); } else if (position >= totalNodes - 1) { AddTail(data); } else { int index = 0; Node *currentNode = head; for (; index next; } // since currentNode points to the node at the given position // we need to insert before since then, the new node // will occupy the given position InsertBefore(currentNode, data); } }

template typename LinkedList::Node *LinkedList::Find(T searchData) { Node *currentNode = head; while (currentNode != nullptr) { if (currentNode->data == searchData) { return currentNode; } currentNode = currentNode->next; } return nullptr; }

template int LinkedList::NodeCount() const { return totalNodes; }

template void LinkedList::PrintForward() { Node *currentNode = head; while (currentNode != nullptr) { std::cout data next; } }

template LinkedList::~LinkedList() { Node *currentNode = head; Node *next = nullptr; while (currentNode != nullptr) { next = currentNode->next; delete currentNode; currentNode = next; } }

#endif//LINKEDLIST_H

-ERROR-

nullptr) { head = newNode; tail = newNode; } else { tail->next

= newNode; newNode->prev = tail; tail = newNode; } totalNodes++; } template

void LinkedList::AddHead(T data) { Node *newNode = new Node(data); if (tail ==

nullptr && head == nullptr) { head = newNode; tail = newNode;

} else { newNode->next = head; head->prev = newNode; head = newNode;

} totalNodes++; } template void LinkedList::InsertAfter(LinkedList::Node *currentNode, T data) { Node *newNode

= new Node(data); Node *nextNode = currentNode->next; // connecting links to the

For this part you will implement functionality to insert elements into the linked list, one of the primary advantages of this data structure. (This can be achieved with arrays as well, but it is much faster with a linked list). You will implement the following: - InsertBefore0 - InsertAfter0 - InsertAt 0 In addition, you will implement the equality operator, to test if two lists are equal to one another. - operator== File is marked as read only Current file: main.cpp - () 6970717273747576data.InsertAt("lists",5);data.InsertAt("insert",10);data.InsertAt("nodes",11);data.InsertAt("list.",15);data.PrintForward();cout&, const allocator <_t>& ) /usr/include/c++/9/bits/allocator.h:167:5: note: template argument dec main. cpp:30:13: note: 'LinkedList' is not derived from 'const sto 30 if (a==b) Compilation failed In file included from/usr/include/c++/9/string:55, from /usr/include/c++/9/bits/locale_classes.h: 40 , from /usr/include/c++/9/bits/ios_base.h: 41 , from /usr/include/c++/9/ios: 42 , from /usr/include/c++/9/ostream: 38 , from /usr/include/c++/9/iostream: 39, from main. cpp:2: /usr/include/c++/9/bits/basic_string.h: 6144:5: note: candidate: 'templat 6144 I operator==(const basic_strings _ 1 _ /usr/include/c++/9/bits/basic_string.h: 6144:5: note: template argument main. cpp:30:13: note: 'LinkedList> ' is not derived from 'const stc 30 I if (a==b )

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!