Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Container with constant time for accessing any element, pop from front and push back?

I'm looking for standard container (if any exists) that will have constant time for:

  • access any element by position
  • pop element from the front
  • push element at back

I can program it by myself, but why bother if it could already exist in std?

like image 796
kravemir Avatar asked Dec 16 '22 23:12

kravemir


1 Answers

std::deque is your friend. It's a double-ended queue with random access to elements.

like image 119
Armen Tsirunyan Avatar answered May 21 '23 08:05

Armen Tsirunyan