Question #95712

using deque ( double ended queue) standard template library. develop a program that uses the keyword push_back to add element at the end and push_front to insert element at beginning.
the program should then list the size of the deque.

Expert's answer

#include <deque> // std::deque<>
#include <iostream> // std::cout, std::endl

int main()
{
    // Create a deque (double ended queue)
    std::deque<int> deq;

    // Use the keyword push_back to add element at the end
    int element1 = 10;
    deq.push_back(element1);

    // Use the keyword push_front to insert element at beginning
    int element2 = -101;
    deq.push_front(element2);

    // Output the size of the deque
    std::cout << deq.size() << std::endl;
}
LATEST TUTORIALS
APPROVED BY CLIENTS