English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C++ Deque (Double-ended Queue)
C ++ The Deque push_front() function inserts a new element at the beginning of the deque container, and the size of the container increases by one.
void push_front(value_type val);
valTo add a new value at the beginning.
It does not return any value.
Let's look at a simple example
#include<iostream> #include<deque> using namespace std; int main() { deque<int> d={200,300,400,500}; deque<int>::iterator itr; d.push_front(100); for(itr = d.begin(); itr != d.end();++itr) cout <<*itr << " "; return 0; }
Output:
100 200 300 400 500
In this example, the push_front() function is inserted into the first element2Add new elements before 00, that is100.
Let's look at a simple example
#include<iostream> #include<deque> using namespace std; int main() { deque<string> d={"is","a","programming","language"}; deque<string>::iterator itr; d.push_front("java"); for(itr = d.begin(); itr != d.end();++itr) cout <<*itr << " "; return 0; }
Output:
java is a programming language
In this example, the push_front() function adds a new string before the first string 'is', that is, 'java'.