A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.tutorialspoint.com/cpp_standard_library/cpp_deque_operator_less_than_or_equal_to.htm below:

C++ Deque::operator<=() Function

C++ Deque::operator<=() Function

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.

Syntax

Following is the syntax for std::deque::operator<=() function.

bool operator<= (const deque<T,Alloc>& lhs, const deque<T,Alloc>& rhs);
Parameters Return value

It returns true if the condition holds, otherwise false.

Exceptions

This function never throws exception.

Time complexity

The time complexity of this function is Linear i.e. O(n)

Example

In 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 b
Example

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 b
Example

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