Posts

All about queue STL in c++ for competitive programming( initialization, traversal and methods/functions ) :

queue STL Important Points: It is a type of container adaptor which follows FIFO (First In First Out) rule. Elements are pushed from the back of the container and are extracted from its front. It is same as the queue in c but with a huge advantage of availability of direct functions/methods for many operations. Remember to use the header file #include<queue> before using queue STL. How do i remember FIFO ? Assume a queue (line) of people in front of a ticket counter. Now think of the people as elements and the room as the container (ignore the ticket counter). A person exits the queue from the front. A new person can only enter the queue from the last. A person can only exit the queue only if the people in front of it exits the queue first which means FIFO (First in First out) i.e the person who entered the queue first can only exit the queue first.   deque vs queue: In queue insertion takes place from one end and removal takes place at the other end while in deque insertio

All about deque STL in c++ for competitive programming( initialization, traversal and methods/functions ) :

deque STL Important Points: It is a sequence container with dynamic size that can be expanded or contracted on both ends. deque is also known as double-ended queue. It is same as the double-ended queue in c but with a huge advantage of availability of direct functions/methods for many operations. Remember to use the header file #include<deque> before using deque STL. deque vs other sequence containers: deque is similar to vector STL on the basis of functionality and interface and can be used for similar purposes but both are having different internal structures.  deque provides efficient insertion of the element at the beginning or at the end and performs worse in insertion and removal of elements at the remaining positions.   deque vs queue: In queue insertion takes place from one end and removal takes place at the other end while in deque insertion/removal can be done from any end. We can use iterators with deque but not with queue.     Different ways to initialize a deque ST