Skip to content

Commit c45e424

Browse files
authored
created new entry for pop_front() under deque. (#7723)
* docs updated,created new entry for pop_front() under deque. * minor updates * Update content/cpp/concepts/deque/terms/pop-front/pop-front.md * Update content/cpp/concepts/deque/terms/pop-front/pop-front.md ---------
1 parent 4708ee3 commit c45e424

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
Title: 'pop_front()'
3+
Description: 'Removes the first element from a deque container in C++.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Game Development'
7+
Tags:
8+
- 'Containers'
9+
- 'Deques'
10+
- 'Methods'
11+
- 'STL'
12+
CatalogContent:
13+
- 'learn-c-plus-plus'
14+
- 'paths/computer-science'
15+
---
16+
17+
The **`pop_front()`** method in C++ deque removes or pops the first (front) element from the deque, reducing its size by one.
18+
19+
## Syntax
20+
21+
```pseudo
22+
deque_name.pop_front();
23+
```
24+
25+
**Parameters:**
26+
27+
This method does not take any parameters.
28+
29+
**Return value:**
30+
31+
`pop_front()` does not return anything and removes the first element from the deque
32+
33+
## Example
34+
35+
In this example, the first element of an integer deque is removed, and the updated deque is printed:
36+
37+
```cpp
38+
#include <iostream>
39+
#include <deque>
40+
using namespace std;
41+
42+
int main() {
43+
deque<int> numbers = {10, 20, 30, 40};
44+
45+
// Remove the first element
46+
numbers.pop_front(); // Removes 10
47+
48+
cout << "Deque after pop_front(): ";
49+
for (int num : numbers) {
50+
cout << num << " ";
51+
}
52+
53+
return 0;
54+
}
55+
```
56+
57+
The output of this code is:
58+
59+
```shell
60+
Deque after pop_front(): 20 30 40
61+
```
62+
63+
## Codebyte Example
64+
65+
In this example, the first element of a string deque is removed, and the new front element is displayed:
66+
67+
```codebyte/cpp
68+
#include <iostream>
69+
#include <deque>
70+
using namespace std;
71+
72+
int main() {
73+
deque<string> names = {"Alice", "Bob", "Charlie"};
74+
75+
// Removes the first element
76+
names.pop_front(); // Removes "Alice"
77+
78+
cout << "Front element after pop_front(): " << names.front() << endl;
79+
return 0;
80+
}
81+
```

0 commit comments

Comments
 (0)