operator<
描述 (Description)
C ++函数std::stack::operator《检查第一个堆栈是否小于其他堆栈。
声明 (Declaration)
以下是std :: stack :: operator
C++98
template <class T, class Container>
bool operator< (const stack<T,Container>& stack1,
const stack<T,Container>& stack2);
参数 (Parameters)
stack1 - 第一个堆栈。
stack2 - 第二个堆栈。
返回值
如果第一个堆栈小于秒,则返回true,否则返回false。
异常 (Exceptions)
这个函数永远不会抛出异常。
时间复杂
线性即O(n)
例子 (Example)
以下示例显示了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.pop();
if (s1 < s2)
cout << "Stack s1 is less than s2." << endl;
s1.push(5);
if (!(s1 < s2))
cout << "Stack s1 is not less than s2." << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
Stack s1 is less than s2.
Stack s1 is not less than s2.