本文整理汇总了C++中MyStack::size方法的典型用法代码示例。如果您正苦于以下问题:C++ MyStack::size方法的具体用法?C++ MyStack::size怎么用?C++ MyStack::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyStack
的用法示例。
在下文中一共展示了MyStack::size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: uTest
bool uTest( UnitTest *utest_p)
{
bool thrown_error = false;
//Tested instance
MyStack stack;
stack.push(1);
stack.push(2);
UTEST_CHECK( utest_p, stack.size() == 2);
int second = stack.pop();
int first = stack.pop();
UTEST_CHECK( utest_p, second == 2);
UTEST_CHECK( utest_p, first == 1);
UTEST_CHECK( utest_p, stack.size() == 0);
try
{
stack.pop();
} catch ( MyStack::Error)
{
thrown_error = true;
}
UTEST_CHECK( utest_p, thrown_error);
return utest_p->result();
}
示例2: twoNumsProcess
/* Function: twoNumsProcess()
* Usage: is called by sortTokenByStacks() or getFinalStacksResult() functions
* -----------------------------------------------------------------------------------------//
* Makes single calculation for two top numbers in stack, and return result to
* stackNumbers back.
*
*
* @param stackNumbers Stack of number values for current recursion
* @param stackOperators Stack of operators for current recursion */
void twoNumsProcess(MyStack<double> &stackNumbers, MyStack<string> &stackOperators) {
/* Stacks elements validation checking for calculating process */
if((stackNumbers.size() - stackOperators.size()) != 1) {
cout << " - CHECK YOUR INPUT, NOT ENOUGH NUMBERS IN FORMULA!" << endl;
failFlag = true;
} else {
/* Calculating process */
double num2 = stackNumbers.pop();
double num1 = stackNumbers.pop();
string thisOper = stackOperators.pop();
double result = singleCalculation(num1, thisOper, num2);
stackNumbers.push(result);
}
}
示例3: getFinalStacksResult
/* Function: getFinalStacksResult()
* Usage: is called by formulaStringScanning() at the end of current recursion.
* -----------------------------------------------------------------------------------------//
* Calculates main result, due to stacks, for current formulaStringScanning() recursion
* stage.
* Precondition: it's end of main formula string or brackets closed process.
*
* @param stackNumbers Stack of number values for current recursion
* @param stackOperators Stack of operators for current recursion */
double getFinalStacksResult(MyStack<double> stackNumbers,
MyStack<string> stackOperators) {
/* Stacks elements validation checking for calculating process */
if((stackNumbers.size() - stackOperators.size()) != 1) {
cout << " - CHECK YOUR INPUT, NOT ENOUGH NUMBERS IN FORMULA!" << endl;
failFlag = true;
}
/* Lunches calculations for all remain values from stacks */
while(!stackOperators.isEmpty()) {
if(failFlag) break;//Some fails appear during calculations
/* Calculation for two top stack numbers and single top operator */
twoNumsProcess(stackNumbers, stackOperators);
}
/* If all operators are processed - end result value remains at top of numbers stack */
if(!failFlag) {
return stackNumbers.pop();
} else {
return 0;
}
}
示例4: main
int main() {
MyStack<int> st;
for (int i = 0; i < 100; i++)
st.push(i);
std::cout << st.size() << std::endl << std::endl;
for (int i = 0; i < 10; i++)
st.pop();
std::cout << st.size() << std::endl << std::endl;
for (int i = 0; i < 10; i++)
st.push(i);
std::cout << st.size() << std::endl << std::endl;
while (!st.empty()) {
int k;
st.top(k);
std::cout << k << std::endl;
st.pop();
}
std::cout << st.size() << std::endl << std::endl;
return 0;
}