Tuesday, January 31, 2017

Runtime complexity of STL Queue

Runtime complexity of STL Queue

Queue

In the C++ STL, a queue is a container adaptor. That means there is no primitive queue data structure. Instead, you create a queue from another container, like a list, and the queue's basic operations will be implemented using the underlying container's operations.
Don't confuse a queue with a deque.

Header

#include <queue>

Constructors

queue< container<T> > q; Make an empty queue. O(1)

Accessors

q.front(); Return the front element. O(1)
q.back(); Return the rear element. O(1)
q.size(); Return current number of elements. O(1)
q.empty(); Return true if queue is empty. O(1)

Modifiers

q.push(value); Add value to end. Same for push_back() for underlying container.
q.pop(); Remove value from front. O(1)

No comments:

Post a Comment