C++ List 库 - operator>= 函数
描述
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);
参数
first − 第一个列表对象。
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