Question: C++ language C++ language I need to add these functionalities and then test them Clear() The purpose of the clear function is to reset the

C++ language C++ language I need to add these functionalities and thenC++ language

test them Clear() The purpose of the clear function is to reset

the list. Zero size, no nodes, everything back to the default. So

C++ language

I need to add these functionalities and then test them

Clear() The purpose of the clear function is to reset the list. Zero size, no nodes, everything back to the default. So basically everything the destructor is doing, except for resetting the first, last, and size. I recommend you just take the code out of the destructor and move it to Clear, then you can simply call Clear() inside your destructor to clean up all the nodes.

Push_Front() Push_front is just the opposite of push_back, adding a new node to the beginning of the list. Dont forget to update the old First pointer, and make sure you do it after the old First has been correctly linked to the new node. Also keep in mind that when adding the first node of the list, you will also need to make sure the last node is updated and not nullptr anymore.

Erase()

Erase should traverse to a node based off a passed-in index, and then delete that node. Erase will also need to make sure that it doesnt impact the list around it. That is, the surrounding nodes should both connect to each other and act as if the targeted node was never there to begin with. Remember, there are also three special cases: If Im deleting the only node in the list, if Im deleting the first node, and if Im deleting the last node. Those, coupled with the generic case, means you could have potentially four different steps to this problem.

Insert()

Testing Make an instance of your DList in main, and give it the works. Push_front, push_back, clear, destructor, go nuts.

#pragma once #include template class DList private: struct node node* next, *prev; Type data; node (Type& _data, node* _prev) : data(_data), prev (_prev), nex int count; node* first, *last; public: DList) first- last -nullptr; count -0;) ~DList (O int GetCount () return count; ) void push_back (Type _data) Type& operator[l (int _index) const Type& operator[ (int _index) const; TH void DList: :push_back (Type_data) node* n - new node( data, last); if (last) else last-next n; = first = n; last n; ++count; template DList:DList () //Fun chance to be terrible tem plate Type& DList: :operator [] (int index) node* tempfirst; int i-0; for (; i data; template Type& DList: :operator [] (int _index) node* tempfirst; int i- 0; for ( inext; return temp->data; template const Type& DList: :operator[] (int _index) const node* temp first,; int i0 for (; i next; return temp->data

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!