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


C++ Stack::BinaryOperation方法代码示例

本文整理汇总了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;
}
开发者ID:brokenprogrammer,项目名称:Expression-Parser,代码行数:30,代码来源:Calculator.c

示例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;
    }
}
开发者ID:brokenprogrammer,项目名称:Expression-Parser,代码行数:18,代码来源:Stack.c


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