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_queue_operator_greater_than_or_equal_to.htm below:

C++ Queue Operator Greater Than or Equal To

C++ Queue::operator>=() Function

The C++ std::queue::operator>= function for the queue is used to compare two queues. It checks whether the first queue is greater than or equal to the second queue based on the lexicographical comparison. It return a boolean value true if the first queue element is greater than or equal to the corresponding elements of the second queue. The time complexity of this function is linear i.e.O(n).

Syntax

Following is the syntax for std::queue::operator>= function.

bool operator>= (const queue<T,Container>& q1, const queue<T,Container>& q2);
Parameters Return value

This function returns true if first queue is greater than or equal to second otherwise false.

Example

Let's look the following example, where we are going to demonstrate the usage of operator>= function.

#include <iostream>
#include <queue>
int main()
{
    std::queue<int> a;
    std::queue<int> b;
    a.push(11);
    a.push(2);
    b.push(1);
    b.push(2);
    if (a >= b) {
        std::cout << "Queue1 is greater than or equal to Queue2." << std::endl;
    } else {
        std::cout << "Queue1 is less than Queue2." << std::endl;
    }
    return 0;
}
Output

Output of the above code is as follows −

Queue1 is greater than or equal to Queue2.
Example

Consider the following example, where we are going to initialize the queues with same elements and comparing them.

#include <iostream>
#include <queue>
int main()
{
    std::queue<int> a;
    std::queue<int> b;
    a.push(11);
    a.push(222);
    b.push(11);
    b.push(222);
    if (a >= b) {
        std::cout << "Queue1 is greater than or equal to Queue2." << std::endl;
    } else {
        std::cout << "Queue1 is less than Queue2." << std::endl;
    }
    return 0;
}
Output

If we run the above code it will generate the following output −

Queue1 is greater than or equal to Queue2.
Example

In the following example, we are going to initialize the queue with single element and comparing them.

#include <iostream>
#include <queue>
int main()
{
    std::queue<int> a;
    std::queue<int> b;
    a.push(1);
    b.push(2);
    if (a >= b) {
        std::cout << "Queue1 is greater than or equal to Queue2." << std::endl;
    } else {
        std::cout << "Queue1 is less than Queue2." << std::endl;
    }
    return 0;
}
Output

Let us compile and run the above program, this will produce the following result −

Queue1 is less than Queue2.
Example

Following is the example, where we are going to compare the empty queue and observing the output.

#include <iostream>
#include <queue>
int main()
{
    std::queue<int> a;
    std::queue<int> b;
    if (a >= b) {
        std::cout << "Queue1 is greater than or equal to Queue2." << std::endl;
    } else {
        std::cout << "Queue1 is less than Queue2." << std::endl;
    }
    return 0;
}
Output

If we run the above code it will generate the following output −

Queue1 is greater than or equal to Queue2.

queue.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