当前位置: 首页>>代码示例>>C++>>正文


C++ stack::isempty方法代码示例

本文整理汇总了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;
}
开发者ID:yao23,项目名称:AppliedDataStructure_CPP,代码行数:43,代码来源:arithmetic_expr_stack.cpp

示例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;
}
开发者ID:vikas-reddy,项目名称:iiith-programming,代码行数:42,代码来源:AVLtree.cpp


注:本文中的stack::isempty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。