![]() |
In C++, deques also called double-ended queues are sequence containers that can perform insertions and deletions on both ends. In this article, we will learn how to access the first element of a deque in C++. Example: Input: myDeque = {1,2,3,4,5} Output: Deque Elements: 1 2 3 4 5 First Element: 1 Accessing the First Element of a Deque in C++To access the first element of a std::deque in C++, we can use the std::deque::front() method which returns a reference to the first element of the deque. This function is suitable for accessing and manipulating the first element without modifying the deque’s structure. Syntaxdeque_name.front();
Here:
C++ Program to Access the First Element of a DequeThe below program demonstrates how we can access the first element of a deque in C++.
Output Deque Elements: 1 2 3 4 5 First Element: 1 Time Complexity: O(1) |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |