From 78e9dc4c7ab328bceae0b6126183f06621308371 Mon Sep 17 00:00:00 2001 From: AmirSoroush Date: Mon, 31 Jul 2023 22:53:42 +0300 Subject: [PATCH] Update data_structures/stacks/infix_to_postfix_conversion.py Co-authored-by: Tianyi Zheng --- .../stacks/infix_to_postfix_conversion.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/data_structures/stacks/infix_to_postfix_conversion.py b/data_structures/stacks/infix_to_postfix_conversion.py index 9db38e298..cd1840f91 100644 --- a/data_structures/stacks/infix_to_postfix_conversion.py +++ b/data_structures/stacks/infix_to_postfix_conversion.py @@ -88,14 +88,14 @@ def infix_to_postfix(expression_str: str) -> str: if char_precedence > tos_precedence: stack.push(char) break - elif char_precedence == tos_precedence: - if associativity(char) == "RL": - stack.push(char) - break - else: - postfix.append(stack.pop()) - else: + if char_precedence < tos_precedence: postfix.append(stack.pop()) + break + # Precedences are equal + if associativity(char) == "RL": + stack.push(char) + break + postfix.append(stack.pop()) while not stack.is_empty(): postfix.append(stack.pop())