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


C++ TStack::top方法代码示例

本文整理汇总了C++中TStack::top方法的典型用法代码示例。如果您正苦于以下问题:C++ TStack::top方法的具体用法?C++ TStack::top怎么用?C++ TStack::top使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TStack的用法示例。


在下文中一共展示了TStack::top方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

const CErrorStack::SError &CErrorStack::Check()
{
    TStack *cStack = m_cErrors.get();
    return cStack->top();
}
开发者ID:kfazi,项目名称:Engine,代码行数:5,代码来源:errorstack.cpp

示例2: do_command

bool do_command(char command, TStack &numbers)
/*Pre: The first parameter specifies a valid calculator command
  Post: The command specified by the first parameter has been applied to the 
		stack of numbers given by the second parameter. A result of true is returned
		unless commnad == 'q'.*/
{
	stack_entry p,q;
	switch(command)
	{
	case '?':
		cout<<"Enter a real number:"<<flush;
		cin>>p;
		if(numbers.push(p) == overflow)
			cout<<"Warning: Stack full, lost number"<<endl;
		break;
	case '=':
		if(numbers.top(p) == underflow)
			cout<<"Stack empty"<<endl;
		else
			cout<<p<<endl;
		break;
	case '+':
		if(numbers.top(p) == underflow)
			cout<<"Stack empty"<<endl;
		else{
			numbers.pop();
			if(numbers.top(q) == underflow){
				cout<<"Stack has just one entry"<<endl;
				numbers.push(p);
			}
			else
			{
				numbers.pop();
				if(numbers.push(p+q) == overflow)
					cout<<"Warning: Stack full, lost result"<<endl;
			}
		}
		break;
	case '-':
		if(numbers.top(p) == underflow)
			cout<<"Stack empty"<<endl;
		else{
			numbers.pop();
			if(numbers.top(q) == underflow){
				cout<<"Stack has just one entry"<<endl;
				numbers.push(p);
			}
			else
			{
				numbers.pop();
				if(numbers.push(p-q) == overflow)
					cout<<"Warning: Stack full, lost result"<<endl;
			}
		}
		break;
	case '*':
		if(numbers.top(p) == underflow)
			cout<<"Stack empty"<<endl;
		else{
			numbers.pop();
			if(numbers.top(q) == underflow){
				cout<<"Stack has just one entry"<<endl;
				numbers.push(p);
			}
			else
			{
				numbers.pop();
				if(numbers.push(p*q) == overflow)
					cout<<"Warning: Stack full, lost result"<<endl;
			}
		}
		break;
		case '/':
		if(numbers.top(p) == underflow)
			cout<<"Stack empty"<<endl;
		else{
			numbers.pop();
			if(numbers.top(q) == underflow){
				cout<<"Stack has just one entry"<<endl;
				numbers.push(p);
			}
			else
			{
				numbers.pop();
				if(numbers.push(p/q) == overflow)
					cout<<"Warning: Stack full, lost result"<<endl;
			}
		}
		break;
		case 'q':
			cout<<"Calculation finished.\n";
			return false;
	}
	return true;
}
开发者ID:wty1990000,项目名称:TY_repository,代码行数:95,代码来源:reversePolish.cpp


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