I have just started with my Data Structures and I am implementing some sort of arrayed list (~=std::vector). I was wondering how is pop_back() implemented so that it has constant complexity? It has to reduce the size by 1 and delete the last element. Now I saw somewhere that it basically reduces the size by 1 and destroys last element via some iterator/pointer, but then why couldn't we implement pop_front() the same way and just redirect our pointer to first element to the next one?
template <typename T>
ArrayList<T>& ArrayList<T>::pop_back()
{
--size_;
auto p = new T[size_];
std::copy(elements_,elements_+size_,p);
delete [] elements_; //elements_ being my pointer
elements_ = p;
return *this;
}