std::dequemy_deque; my_deque.push_back(10); my_deque.push_front(20); my_deque.push_front(30); my_deque.push_front(40); // The deque contents: [40, 30, 20, 10]
#includeIn this example, a deque of characters is created with 2 elements, both initialized with the letter 'a'. The push_front() function is used three times to insert the characters 'b', 'c' and 'd' at the front of the deque. The resulting deque is printed to the console. The std::deque container is part of the standard template library (STL) in C++. Therefore, the library package that needs to be included to use this function would be#include int main() { std::deque my_deque (2, 'a'); my_deque.push_front('b'); my_deque.push_front('c'); my_deque.push_front('d'); for (auto& elem : my_deque) std::cout << elem << " "; return 0; } // Output: "d c b a a"