C++ Stack 库 - operator> 函数
描述
C++ 函数 std::stack::operator> 检查第一个堆栈是否大于其他堆栈。
声明
以下是 std::stack::operator> 函数形式 std::stack 头的声明。
C++98
template <class T, class Container>
bool operator> (const stack<T,Container>& stack1,
const stack<T,Container>& stack2);
参数
stack1 − 第一个堆栈。
stack2 − 第二个堆栈。
返回值
如果第一个堆栈大于其他堆栈,则返回 true。
异常
此函数从不抛出异常。
时间复杂度
线性,即 O(n)
示例
以下示例显示了 std::stack::operator> 函数的用法。
#include <iostream>
#include <stack>
using namespace std;
int main(void) {
stack<int> s1;
stack<int> s2;
for (int i = 0; i < 5; ++i) {
s1.push(i + 1);
s2.push(i + 1);
}
s1.push(6);
if (s1 > s2)
cout << "Stack s1 is greater than s2." << endl;
s2.push(7);
if (!(s1 > s2))
cout << "Stack s1 is not greater than s2." << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
Stack s1 is greater than s2. Stack s1 is not greater than s2.

