Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double getValue( ExpNode *node ) { // Return the value of the expression represented by // the tree to which node refers. Node must be non-NULL.
- if ( node->kind == NUMBER ) { // The value of a NUMBER node is the number it holds.
- return node->number;
- }
- else { // The kind must be OPERATOR. // Get the values of the operands and combine them
- // using the operator.
- double leftVal = getValue( node->left )
- double rightVal = getValue( node->right );
- switch ( node->op ) {
- case '+': return leftVal + rightVal;
- case '-': return leftVal - rightVal;
- case '*': return leftVal * rightVal;
- case '/': return leftVal / rightVal;
- }
- }
- } // end getValue()
- double getValue( ExpNode *node ) {
- if (node==NULL)
- return (double)INT_MAX; //include limits.h and don't use the value INT_MAX in any node
- //rest code
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement