Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------image text in transcribed

-MAIN.CPP-

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

-LEAKER.H-

image text in transcribed image text in transcribed image text in transcribedimage text in transcribed image text in transcribedimage text in transcribed

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

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-

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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

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

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

9. Power and politics can be destructive forces in organizations.

Answered: 1 week ago

Question

1. What is meant by Latitudes? 2. What is cartography ?

Answered: 1 week ago

Question

What is order of reaction? Explain with example?

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago