本文整理汇总了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();
}
示例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;
}