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 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
