Question: my code #include DoublyLinkedList.h #include DoublyLinkedListIterator.h #include #include #include template class List { private: using Node = typename DoublyLinkedList::Node; Node fHead; Node fTail;

my code
#include "DoublyLinkedList.h"
#include "DoublyLinkedListIterator.h"
#include
#include
#include
template
class List
{
private:
using Node = typename DoublyLinkedList::Node;
Node fHead;
Node fTail;
size_t fSize;
public:
using Iterator = DoublyLinkedListIterator;
List() noexcept
: fHead(nullptr), fTail(nullptr), fSize(0){}
List(const List& aOther)
: fHead(nullptr), fTail(nullptr), fSize(0)
{
for (auto current = aOther.fHead; current != nullptr; current = current->fNext)
{
push_back(current->fData);
}
}
List& operator=(const List& aOther)
{
if (this != &aOther)
{
List temp(aOther);
swap(temp);
}
return *this;
}
List(List&& aOther) noexcept
: fHead(aOther.fHead), fTail(aOther.fTail), fSize(aOther.fSize)
{
aOther.fHead = nullptr;
aOther.fTail = nullptr;
aOther.fSize =0;
}
List& operator=(List&& aOther) noexcept
{
if (this != &aOther)
{
deleteAll();
fHead = aOther.fHead;
fTail = aOther.fTail;
fSize = aOther.fSize;
aOther.fHead = nullptr;
aOther.fTail = nullptr;
aOther.fSize =0;
}
return *this;
}
void swap(List& aOther) noexcept
{
std::swap(fHead, aOther.fHead);
std::swap(fTail, aOther.fTail);
std::swap(fSize, aOther.fSize);
}
~List()
{
deleteAll();
}
size_t size() const noexcept
{
return fSize;
}
template
void push_front(U&& aData)
{
auto newNode = DoublyLinkedList::makeNode(std::forward(aData));
if (!fHead)
{
fHead = fTail = newNode;
}
else
{
newNode->fNext = fHead;
fHead->fPrevious = newNode;
fHead = newNode;
}
++fSize;
}
template
void push_back(U&& aData)
{
auto newNode = DoublyLinkedList::makeNode(std::forward(aData));
if (!fTail)
{
fHead = fTail = newNode;
}
else
{
newNode->fPrevious = fTail;
fTail->fNext = newNode;
fTail = newNode;
}
++fSize;
}
void remove(const T& aElement) noexcept
{
for (auto current = fHead; current != nullptr; current = current->fNext)
{
if (current->fData == aElement)
{
if (auto prev = current->fPrevious.lock())
prev->fNext = current->fNext;
else
fHead = current->fNext;
if (current->fNext)
current->fNext->fPrevious = current->fPrevious;
else
fTail = current->fPrevious.lock();
current->isolate();
--fSize;
return;
}
}
}
const T& operator[](size_t aIndex) const
{
if (aIndex >= fSize)
throw std::out_of_range("Index out of bounds");
auto current = fHead;
for (size_t i =0; i < aIndex; ++i)
{
current = current->fNext;
}
return current->fData;
}
Iterator begin() const noexcept
{
return Iterator(fHead, fTail);
}
Iterator end() const noexcept
{
return Iterator(nullptr, nullptr);
}
Iterator rbegin() const noexcept
{
return Iterator(fTail, fHead);
}
Iterator rend() const noexcept
{
return Iterator(nullptr, nullptr);
}
private:
void deleteAll()
{
while (fHead)
{
auto next = fHead->fNext;
fHead->isolate();
fHead = next;
}
fTail = nullptr;
fSize =0;
}
};
the error im getting
Exception thrown: read access violation.
**this** was nullptr.
at this code in the xstring file
))

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!