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;
sizet fSize;
public:
using Iterator DoublyLinkedListIterator;
List noexcept
: fHeadnullptr fTailnullptr fSize
Listconst List& aOther
: fHeadnullptr fTailnullptr fSize
for auto current aOther.fHead; current nullptr; current currentfNext
pushbackcurrentfData;
List& operatorconst List& aOther
if this &aOther
List tempaOther;
swaptemp;
return this;
ListList&& aOther noexcept
: fHeadaOtherfHead fTailaOtherfTail fSizeaOtherfSize
aOther.fHead nullptr;
aOther.fTail nullptr;
aOther.fSize ;
List& operatorList&& aOther noexcept
if this &aOther
deleteAll;
fHead aOther.fHead;
fTail aOther.fTail;
fSize aOther.fSize;
aOther.fHead nullptr;
aOther.fTail nullptr;
aOther.fSize ;
return this;
void swapList& aOther noexcept
std::swapfHead aOther.fHead;
std::swapfTail aOther.fTail;
std::swapfSize aOther.fSize;
~List
deleteAll;
sizet size const noexcept
return fSize;
template
void pushfrontU&& aData
auto newNode DoublyLinkedList::makeNodestd::forwardaData;
if fHead
fHead fTail newNode;
else
newNodefNext fHead;
fHeadfPrevious newNode;
fHead newNode;
fSize;
template
void pushbackU&& aData
auto newNode DoublyLinkedList::makeNodestd::forwardaData;
if fTail
fHead fTail newNode;
else
newNodefPrevious fTail;
fTailfNext newNode;
fTail newNode;
fSize;
void removeconst T& aElement noexcept
for auto current fHead; current nullptr; current currentfNext
if currentfData aElement
if auto prev currentfPrevious.lock
prevfNext currentfNext;
else
fHead currentfNext;
if currentfNext
currentfNextfPrevious currentfPrevious;
else
fTail currentfPrevious.lock;
currentisolate;
fSize;
return;
const T& operatorsizet aIndex const
if aIndex fSize
throw std::outofrangeIndex out of bounds";
auto current fHead;
for sizet i ; i aIndex; i
current currentfNext;
return currentfData;
Iterator begin const noexcept
return IteratorfHead fTail;
Iterator end const noexcept
return Iteratornullptr nullptr;
Iterator rbegin const noexcept
return IteratorfTail fHead;
Iterator rend const noexcept
return Iteratornullptr nullptr;
private:
void deleteAll
while fHead
auto next fHeadfNext;
fHeadisolate;
fHead next;
fTail nullptr;
fSize ;
;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
