Queues: Limited or Unlimited Size?
Hi,
I am learning queues and I have found 2 examples. Both examples represent queues with limited size, for example 30.
But <queue> allows us to create queue that is not limited by *pre-set queue size.
Can anyone explain me how have they created something like that?
Thanks!
By *pre-set I wanted to say that we have set the queue size during its initialization. Like when we create the arrays.
10 Minutes
Discussion Span
MrEARTHSHAcKER
Junior Poster in Training
77 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0
The default back-end for std::queue is std::deque, which grows and shrinks dynamically. std::queue is actually a form of adapter that sits on top of a data structure to provide a convenient interface. std::stack is the same way.
std::deque is implemented in a somewhat confusing way, so you might consider studying how std::vector works intead (it's basically a dynamic array). It grows dynamically as well, but in a much more intuitive manner. That should get you rolling on answering the question: "how have they created something like that?". :)
deceptikon
Challenge Accepted
3,457 posts since Jan 2012
Reputation Points: 822
Solved Threads: 474
Skill Endorsements: 57
MrEARTHSHAcKER
Junior Poster in Training
77 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
Skill Endorsements: 0