C++ 列表库 - 运算符 >= 函数


描述

C++ 函数std::list::operator>=测试第一个列表是否大于或等于其他列表。

宣言

以下是 std::list::operator>= 函数形式 std::list 标头的声明。

C++98

template <class T, class Alloc>
bool operator>= (const list<T,Alloc>& first, const list<T,Alloc>& second);

参数

  • 第一个- 第一个列表对象。

  • 第二个- 相同类型的第二个列表对象。

返回值

如果第一个列表大于或等于第二个列表,则返回 true,否则返回 false。

例外情况

这个函数永远不会抛出异常。

时间复杂度

线性即 O(n)

例子

以下示例显示了 std::list::operator>= 函数的用法。

#include <iostream>
#include <list>

using namespace std;

int main(void) {
   list<int> l1 = {1, 2, 3};
   list<int> l2 = {1, 2, 3};

   if (l1 >= l2)
      cout << "List l1 is greater that or equal to l2" << endl;

   l1.pop_back();

   if (!(l1 >= l2))
      cout << "List l1 is not greater that or equal to l2" << endl;

   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

List l1 is greater that or equal to l2
List l1 is not greater that or equal to l2
列表.htm