Question: c language c language i need to add these functionalities...
I need to add these functionalities and then test them
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 is just the opposite of push_back, adding a new node to the beginning of the list. Don’t forget
to update the old First pointer, and make sure you do it after the old First has been correctly linked to the
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 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 doesn’t 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 I’m deleting the only node in the list, if I’m deleting the
first node, and if I’m deleting the last node. Those, coupled with the generic case, means you could have
potentially four different steps to this problem.
Make an instance of your DList in main, and give it the works. Push_front, push_back, clear, destructor, go