C++ 列表庫 - operator> 函式



描述

C++ 函式std::list::operator> 測試第一個列表是否大於其他列表。

宣告

以下是來自 std::list 標頭檔案的 std::list::operator> 函式的宣告。

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, 4};
   list<int> l2 = {1, 2, 3};

   if (l1 > l2)
      cout << "List l1 is greater that l2" << endl;

   l1.pop_back();

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

   return 0;
}

讓我們編譯並執行上述程式,這將產生以下結果:

List l1 is greater that l2
List l1 is not greater that l2
list.htm
廣告

© . All rights reserved.