本文整理汇总了C++中LinkedStack::top2方法的典型用法代码示例。如果您正苦于以下问题:C++ LinkedStack::top2方法的具体用法?C++ LinkedStack::top2怎么用?C++ LinkedStack::top2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinkedStack
的用法示例。
在下文中一共展示了LinkedStack::top2方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: eval
void eval(LinkedStack& op, LinkedStack& num) {
int numtop = num.top2();
num.pop();
if (op.top() == "+")
numtop = add(num.top2(),numtop);
else if (op.top() == "-")
numtop = subtract(num.top2(),numtop);
else if (op.top() == "*")
numtop = multiply(num.top2(),numtop);
else if (op.top() == "/")
numtop = divide(num.top2(),numtop);
op.pop(), num.pop();
num.push(numtop);
}
示例2: expressionMain
void expressionMain() {
LinkedStack expressionNum;
LinkedStack expressionOp;
int choice = 1, num;
string op, expression = "", numS;
stringstream ss;
cout << "Please enter your expression one character at a time." << endl;
cout << "num:";
num = enterNum();
ss << num;
ss >> numS;
expression += numS;
expressionNum.push(num);
while (choice != 3) {
switch (choice) {
case 1: cout << "op:";
op = enterOp();
cout << "num:";
num = enterNum();
ss.clear();
ss << num;
ss >> numS;
expression += op + numS;
if (!expressionOp.empty() && opSize(expressionOp.top()) >= opSize(op)) {
eval(expressionOp,expressionNum);
if (!expressionOp.empty() && opSize(expressionOp.top()) >= opSize(op)) {
eval(expressionOp,expressionNum);
}
expressionOp.push(op);
expressionNum.push(num);
}
else {
expressionOp.push(op);
expressionNum.push(num);
}
cout << "Expression: " << expression << endl;
cout << "More(1),Quit(2)?: ";
cin >> choice;
break;
case 2: while (!expressionOp.empty())
eval(expressionOp,expressionNum);
cout << "Answer: " << expressionNum.top2() << endl;
choice = 3;
}
}
}