本文整理汇总了C++中stack::isempty方法的典型用法代码示例。如果您正苦于以下问题:C++ stack::isempty方法的具体用法?C++ stack::isempty怎么用?C++ stack::isempty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stack
的用法示例。
在下文中一共展示了stack::isempty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
int result; // for result of expression
char OP; // temporary for operator symbol
char symbol[100]; // to store expression symbols
while (cin >> symbol)
{
int symboltype = classify(symbol);
switch (symboltype)
{
case oprand: operandstack.push(atoi(symbol)); // oprand is pushed
break; // on operand stack
case openparen: operatorstack.push('('); // open paren is pushed
break; // on operator stack
case closeparen: while(true) // pop and apply operators
{ operatorstack.pop(OP); // until open paren is
if (OP=='(') break; // found. Pop it
else apply(OP);
}
break;
case oprator: while(true)
{ // pop and apply
if (operatorstack.isempty()) break; // operators
operatorstack.gettop(OP); // until stack is
if (priority(OP) < priority(symbol[0])) // empty or top
break; // has lower
operatorstack.pop(OP); // priority than
apply(OP); // operator just
} // read
operatorstack.push(symbol[0]);
}
}
while (operatorstack.pop(OP)) apply(OP); // pop and apply any operators
operandstack.pop(result); // top operand is result
cout << result << endl;
return 0;
}
示例2: balance
void AVLTree::balance(stack S)
// Balance the tree given the stack of pointers
{
tnode *temp=NULL;
for( temp=NULL; !S.isempty() ; temp = S.gettop(),S.pop() )
{
if( balance_fact(S.gettop()) <-1 )
{
if( balance_fact(temp) > 0 )
{
cout<<" Right at "
<<temp->data<<" + Left at "
<<S.gettop()->data<<" \n";
right_rotate(temp);
left_rotate( S.gettop() );
}
else
{
cout<<" Left at "<< S.gettop()->data<<"\n";
left_rotate( S.gettop() );
}
}
if( balance_fact(S.gettop()) >1 )
{
if( balance_fact(temp) < 0 )
{
cout<<" Left at "
<<temp->data<<" + Right at "
<<S.gettop()->data<<" \n";
left_rotate( temp );
right_rotate( S.gettop() );
}
else
{
cout<<" Right at "<< S.gettop()->data<<"\n";
right_rotate( S.gettop() );
}
}
}
return;
}