Question
how to insert, my code doesnt work. // Insert a piece of data *before* the passed-in iterator // // In: _iter The iterator // _data
how to insert, my code doesnt work.
// Insert a piece of data *before* the passed-in iterator // // In: _iter The iterator // _data The value to add // // Example: /* Before
0<-[4]<->[5]<->[6]->0 I
After
0<-[4]<->[9]<->[5]<->[6]->0 I */ // Return: The iterator // SPECIAL CASE: Inserting at head or empty list // NOTE: The iterator should now be pointing to the new node created
Iterator Insert(Iterator& _iter, const T& _data) { Node* node = new Node(_data); if (_iter.mCurr == mTail) { mTail = node; _iter.mCurr->next = node; } return _iter; }
need help with clear method;
// Clear the list of all dynamic memory // Resets the list to its default state
void Clear() { mSize = 0; Node* temp = mHead; /*mHead = nullptr; mTail = nullptr;*/ mHead = mTail = nullptr; while (temp) { Node* node = temp->next; delete temp; temp = node; } delete mTail; }
how to assign this properly
data members are:
mHead;
mTail;
mSize;
also default constructor sets next, prev, and data
// Assignment operator // Used to assign one object to another // In: _asign The object to assign from // // Return: The invoking object (by reference) // This allows us to daisy-chain
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started