Advertisement
Guest User

Untitled

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