Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. double getValue( ExpNode *node ) { // Return the value of the expression represented by // the tree to which node refers. Node must be non-NULL.
  2. if ( node->kind == NUMBER ) { // The value of a NUMBER node is the number it holds.
  3. return node->number;
  4. }
  5. else { // The kind must be OPERATOR. // Get the values of the operands and combine them
  6. // using the operator.
  7. double leftVal = getValue( node->left )
  8. double rightVal = getValue( node->right );
  9.  
  10. switch ( node->op ) {
  11. case '+': return leftVal + rightVal;
  12. case '-': return leftVal - rightVal;
  13. case '*': return leftVal * rightVal;
  14. case '/': return leftVal / rightVal;
  15. }
  16. }
  17. } // end getValue()
  18.  
  19. double getValue( ExpNode *node ) {
  20. if (node==NULL)
  21. return (double)INT_MAX; //include limits.h and don't use the value INT_MAX in any node
  22.  
  23. //rest code
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement