C++ Double-ended Queues

Double-ended queues are like vectors, except that they allow fast insertions and deletions at the beginning (as well as the end) of the container. The below is a demonstration of how the Deque works. 




Container Constructors

  • assign - assign elements to a dequeue
  • at - returns an element at a specific location
  • back - returns a reference iterator to the last element of a dequeue
  • begin - returns a reference iterator to the beginning to the dequeue
  • clear - deletes all elements from the dequeue
  • empty - Returns true(1) if the dequeue has no elements else return false(0)
  • end - returns  a reference iterator just past the last element of a dequeue
  • erase - removes elements from a dequeue
  • front - returns a reference iterator to the first element of a dequeue
  • insert - inserts an item into the dequeue
  • max_size - outputs the number of a maximum number of elements that the dequeue can hold
  • pop_back - removes the last element of a dequeue
  • pop_front - removes the first element of the dequeue
  • push_back - add an element to the end of the dequeue
  • push_front - add an element to the front of the dequeue
  • rbegin - returns a reverse iterator to the beginning of the dequeue
  • resize - change the size of the dequeue
  • size - outputs the number of items in the dequeue
  • swap - swap the contents of this dequeue with another
Below is the implementation of these functions.

Here we implement front(), back(), push_back(), push_front(), pop_back(), pop_front() etc.

In the below code we implement at(), clear(), empty(), insert().

If you find any error or have some suggestions then please do comment.

Thank You
Happy Coding!!!
Cheers!

Comments