Deletion Method In C++
he following methods are available for deleting objects in the container classes vector, deque, and list: pop_back() deletes the last object in the container erase() deletes the object at a given position, or deletes all the objects in a given range clear() deletes all the objects in a container. The following method is additionally defined in the deque and list classes: pop_front() deletes the first object in the container. The method does not have a return value, just like the pop_back() method. The pop_back() and pop_front() methods are preferable on account of their constant runtimes. Using the erase() method to delete an object at the beginning or in the middle of a container also provides a constant runtime in the container class list. However, the runtime is linear in the vector and deque classes, since objects must be shifted within the container to fill the gap left by the deletion.
© 2016-2019, Codeverb.com - All Rights Reserved