Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. void mathProcessor::compute(binaryTreeNode<string> *p){
  2. while (p != NULL) {
  3. compute(p->llink);
  4. compute(p->rlink);
  5. /* isOperator(p->info[0]);*/
  6. if((p->info[0]) != '+' && (p->info[0]) != '-' && (p->info[0]) != '*' && (p->info[0]) != '/'){
  7. theStack.push(p->info);
  8. }
  9. else {
  10. double num1;
  11. double num2;
  12. double num3;
  13. num1 = convertStringToDouble(theStack.top());
  14. theStack.pop();
  15. num2 = convertStringToDouble(theStack.top());
  16. theStack.pop();
  17. if((p->info[0]) == '+'){
  18. num3 = num1 + num2;
  19. theStack.push(convertDoubleToString(num3));
  20. }
  21. else if((p->info[0]) == '-'){
  22. num3 = num1 - num2;
  23. theStack.push(convertDoubleToString(num3));
  24. }
  25. else if((p->info[0]) == '*'){
  26. num3 = num1 * num2;
  27. theStack.push(convertDoubleToString(num3));
  28. }
  29. else {
  30. num3 = num1 / num2;
  31. theStack.push(convertDoubleToString(num3));
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement