Deque

#include <iostream>
#include <deque>

int main() {
    std::deque<int> myDeque;

    myDeque.push_back(10);
    myDeque.push_back(20);
    myDeque.push_front(5);

    std::cout << "Deque elements:";
    for (auto it = myDeque.begin(); it != myDeque.end(); ++it) {
        std::cout << ' ' << *it;
    }
    std::cout << std::endl;

    std::cout << "Front element: " << myDeque.front() << std::endl;
    std::cout << "Back element: " << myDeque.back() << std::endl;

    myDeque.pop_front();

    std::cout << "Deque elements after pop_front:";
    for (auto it = myDeque.begin(); it != myDeque.end(); ++it) {
        std::cout << ' ' << *it;
    }
    std::cout << std::endl;

    return 0;
}

This code demonstrates the use of a deque (double-ended queue) in C++. It includes the necessary headers and defines a main function. Inside main, a deque of integers named myDeque is created.

Three elements are inserted into the deque using push_back and push_front methods. The elements are 10 and 20 pushed to the back, and 5 pushed to the front.

The code then displays the elements of the deque using a for loop and iterators. After that, it outputs the front and back elements of the deque using front() and back() methods.

Next, it removes the front element from the deque using pop_front().

Finally, it displays the remaining elements in the deque after the pop_front() operation.