如果在运算符左侧的堆栈对象与右侧,的堆栈对象小于测试。
bool operator<(
const stack <Type, Container>& _Left,
const stack <Type, Container>& _Right
);
参数
_Left
类型 stack对象。_Right
类型 stack对象。
返回值
true,如果在运算符左侧的堆栈比和不相等的带有堆栈小于在运算符的右侧;否则 false。
备注
堆栈对象之间的比较根据其元素的比较pairwise。小于两个堆栈对象之间的关系于比较的第一对不相等元素。
示例
// stack_op_lt.cpp
// compile with: /EHsc
#include <stack>
#include <list>
#include <iostream>
int main( )
{
using namespace std;
// Declares stacks with list base container
stack <int, list<int> > s1, s2, s3;
s1.push( 2 );
s1.push( 4 );
s1.push( 6 );
s1.push( 8 );
s2.push( 5 );
s2.push( 10 );
s3.push( 2 );
s3.push( 4 );
s3.push( 6 );
s3.push( 8 );
if ( s1 >= s2 )
cout << "The stack s1 is greater than or equal to "
<< "the stack s2." << endl;
else
cout << "The stack s1 is less than "
<< "the stack s2." << endl;
if ( s1>= s3 )
cout << "The stack s1 is greater than or equal to "
<< "the stack s3." << endl;
else
cout << "The stack s1 is less than "
<< "the stack s3." << endl;
// to print out the stack s1 ( by unstacking the elements):
stack <int>::size_type i_size_s1 = s1.size( );
cout << "The stack s1 from the top down is: ( ";
unsigned int i;
for ( i = 1 ; i <= i_size_s1 ; i++ )
{
cout << s1.top( ) << " ";
s1.pop( );
}
cout << ")." << endl;
}
要求
标头: <stack>
命名空间: std