data_structures.stacks.infix_to_postfix_conversion ================================================== .. py:module:: data_structures.stacks.infix_to_postfix_conversion .. autoapi-nested-parse:: https://en.wikipedia.org/wiki/Infix_notation https://en.wikipedia.org/wiki/Reverse_Polish_notation https://en.wikipedia.org/wiki/Shunting-yard_algorithm Attributes ---------- .. autoapisummary:: data_structures.stacks.infix_to_postfix_conversion.ASSOCIATIVITIES data_structures.stacks.infix_to_postfix_conversion.PRECEDENCES data_structures.stacks.infix_to_postfix_conversion.expression Functions --------- .. autoapisummary:: data_structures.stacks.infix_to_postfix_conversion.associativity data_structures.stacks.infix_to_postfix_conversion.infix_to_postfix data_structures.stacks.infix_to_postfix_conversion.precedence Module Contents --------------- .. py:function:: associativity(char: str) -> Literal['LR', 'RL'] Return the associativity of the operator `char`. https://en.wikipedia.org/wiki/Operator_associativity .. py:function:: infix_to_postfix(expression_str: str) -> str >>> infix_to_postfix("(1*(2+3)+4))") Traceback (most recent call last): ... ValueError: Mismatched parentheses >>> infix_to_postfix("") '' >>> infix_to_postfix("3+2") '3 2 +' >>> infix_to_postfix("(3+4)*5-6") '3 4 + 5 * 6 -' >>> infix_to_postfix("(1+2)*3/4-5") '1 2 + 3 * 4 / 5 -' >>> infix_to_postfix("a+b*c+(d*e+f)*g") 'a b c * + d e * f + g * +' >>> infix_to_postfix("x^y/(5*z)+2") 'x y ^ 5 z * / 2 +' >>> infix_to_postfix("2^3^2") '2 3 2 ^ ^' .. py:function:: precedence(char: str) -> int Return integer value representing an operator's precedence, or order of operation. https://en.wikipedia.org/wiki/Order_of_operations .. py:data:: ASSOCIATIVITIES :type: dict[str, Literal['LR', 'RL']] .. py:data:: PRECEDENCES :type: dict[str, int] .. py:data:: expression :value: 'a+b*(c^d-e)^(f+g*h)-i'