Advertisement
Anan99

Untitled

Apr 19th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. bool Operand(char x) {
  2.  
  3. return (x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z');
  4.  
  5. }
  6. string GetInfix(string exp) //Evaluate to infix
  7. {
  8. StackOFQueue <string> s;
  9.  
  10. for (int i = 0; exp[i] != '\0'; i++)
  11. {
  12. if (Operand(exp[i]))
  13. {
  14. string op(1, exp[i]);
  15. s.push(op);
  16. }
  17. else
  18. {
  19. string op1 = s.top();
  20. s.pop();
  21. string op2 = s.top();
  22. s.pop();
  23. s.push("(" + op2 + exp[i] +op1 + ")");
  24. }
  25. }
  26.  
  27. return s.top();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement