Search code examples
data-structuresdeque

Deque (deck) question


I understand that Deque is "double ended queue" which supports operations from both ends of a queue. My question is how does it work? e.g. say i have numbers 3,4,2,1,5,6 and i perform push_back(4) push_back(3) push_front(5) push_front(1)

how will this data appear in deque? will it be like 3,4,5,1 where Front points to 1 and back to 3? so if i do pop_back() will it return 3 or 4? (since 3 was pushed before 4.. does it act as a FIFO?) similarly for pop_front()? 5 or 1?

if I do push_back(4) push_back(3) push_back(5) push_back(1)

then I did pop_front() ? what will it return? 4 or 1?

Please help me understand .

Thanks in advance


Solution

  • See http://www.cplusplus.com/reference/stl/deque/

    Also, I use cplusplus.com's reference often for STL questions. It's well written and thorough.