Why doesn't std::vector::push_front() exist? [duplicate]

  • A+
Category:Languages

This question already has an answer here:

Since std::vector::push_back() exists, why doesn't std::vector::push_front() exist too?

I know there are others storage objects that work pretty much the same way and have an implementation of both push_back() and push_front() functions, but I was curious about the reason why std::vector doesn't.

 


You don't want to push_front on a vector ever. Adding an element to the front means moving every single other element in the vector one element back: O(n) copying. Terrible performance.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: