The C++ std::deque::operator<=() function is used to compare two deques lexicographically. It returns true if the first deque is lexicographically less than or equal to the second deque otherwise it returns false. The comparison starts from the beginning of the deque and stops as soon as a difference is found.
SyntaxFollowing is the syntax for std::deque::operator<=() function.
bool operator<= (const deque<T,Alloc>& lhs, const deque<T,Alloc>& rhs);Parameters
It returns true if the condition holds, otherwise false.
ExceptionsThis function never throws exception.
Time complexityThe time complexity of this function is Linear i.e. O(n)
ExampleIn the following example, we are going to consider the basic usage of the operator<=() function.
#include <deque> #include <iostream> int main() { std::deque<int> a = {1, 2}; std::deque<int> b = {1, 2, 3}; if (a <= b) { std::cout << "a is less than or equal to b" << std::endl; } else { std::cout << "a is greater than b" << std::endl; } }Output
Output of the above code is as follows −
a is less than or equal to bExample
Consider the following example, where we are going to assign() to add elements to the deque and comparing them.
#include <deque> #include <iostream> int main() { std::deque<int> a = {1, 2}; std::deque<int> b = {1, 2, 3}; b.assign(3,1); if (a <= b) { std::cout << "a is less than or equal to b" << std::endl; } else { std::cout << "a is greater than b" << std::endl; } }Output
Following is the output of the above code −
a is greater than bExample
Let's look at the following example, where we are going to consider the deque with char and comparing them.
#include <deque> #include <iostream> int main() { std::deque<char> a = {'A', 'B', 'C'}; std::deque<char> b = {'D', 'E', 'F'}; if (a <= b) { std::cout << "a is less than or equal to b" << std::endl; } else { std::cout << "a is greater than b" << std::endl; } }Output
If we run the above code it will generate the following output −
a is less than or equal to b
deque.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4