C++ Deque::operator>=() 函式



C++ 的std::deque::operator>=()函式用於按字典順序比較兩個雙端佇列。比較持續進行,直到發現一個雙端佇列大於另一個雙端佇列。如果一個雙端佇列的元素大於或等於另一個雙端佇列的對應元素,則返回true,否則返回false。

語法

以下是std::deque::的語法。

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

引數

  • lhs, rhs − 表示雙端佇列容器。

返回值

如果條件成立,則返回true,否則返回false。

異常

此函式從不丟擲異常。

時間複雜度

此函式的時間複雜度為線性,即 O(n)

示例

在下面的示例中,我們將考慮operator>=()函式的基本用法。

#include <iostream>
#include <deque>
int main()
{
    std::deque<int> a = {10,12,23};
    std::deque<int> b = {01,12,23};
    if (a >= b) {
        std::cout << "a is greater than or equal to b." << std::endl;
    } else {
        std::cout << "a is not greater than or equal to b." << std::endl;
    }
    return 0;
}

輸出

以上程式碼的輸出如下:

a is greater than or equal to b.

示例

考慮以下示例,我們將比較不同大小的雙端佇列。

#include <iostream>
#include <deque>
int main()
{
    std::deque<int> a = {1, 2};
    std::deque<int> b = {1, 2, 4};
    if (a >= b) {
        std::cout << "a is greater than or equal to b." << std::endl;
    } else {
        std::cout << "a is not greater than or equal to b." << std::endl;
    }
    return 0;
}

輸出

以上程式碼的輸出如下:

a is not greater than or equal to b.

示例

讓我們看下面的例子,我們將用字串填充雙端佇列並進行比較。

#include <iostream>
#include <deque>
#include <string>
int main()
{
    std::deque<std::string> a = {"Ducati", "Cheron"};
    std::deque<std::string> b = {"Aston", "Lexus"};
    if (a >= b) {
        std::cout << "a is greater than or equal to b." << std::endl;
    } else {
        std::cout << "a is not greater than or equal to b." << std::endl;
    }
    return 0;
}

輸出

如果我們執行以上程式碼,它將生成以下輸出:

a is greater than or equal to b.
deque.htm
廣告