本文整理汇总了C++中Stack::BinaryOperation方法的典型用法代码示例。如果您正苦于以下问题:C++ Stack::BinaryOperation方法的具体用法?C++ Stack::BinaryOperation怎么用?C++ Stack::BinaryOperation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stack
的用法示例。
在下文中一共展示了Stack::BinaryOperation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calculate
/*
* calculate
* Calculates an parsed expression using one stack for the operations and
* two stack for the operands and operators.
*
* @param **OpStack - The stack of operations.
* @param **OperandStack - The stack of operands.
*/
double calculate(Stack **OpStack, Stack **OperandStack) {
double result = 0;
Stack *current = *OpStack;
for (; current; current = current->next) {
switch (current->opType) {
case binaryOperation:
//Result is always the result of the lastest made operation
result = current->BinaryOperation(pop(OperandStack), pop(OperandStack));
printf("Current result: %f\n", result);
//Pushes the latest result to the operand stack incase it should be used again.
pushOperand(OperandStack, operand, result);
break;
default:
printf("Something else than an operation was found here..\n");
break;
}
}
return result;
}
示例2: display
/**
* display loops through the entire Stacks linked list priting out every
* data property found while looping through the entire list of linked Stacks.
*
* @param *head - The target Stack to loop through its linked elements.
*/
void display(Stack *head) {
Stack *current = head;
while (current != NULL) {
if (current->opType == operand) {
printf("Stack Data: %f, Stack Size: %i\n", current->operand, current->size);
} else if (current->opType == binaryOperation) {
printf("Stack BinaryOperationResult: %c %f, Stack Size: %i\n", current->symbol, current->BinaryOperation(10, 10), current->size);
}
current = current->next;
}
}