Update data_structures/stacks/infix_to_postfix_conversion.py

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
This commit is contained in:
AmirSoroush 2023-07-31 22:53:42 +03:00 committed by GitHub
parent 01aebb0270
commit 78e9dc4c7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,13 +88,13 @@ def infix_to_postfix(expression_str: str) -> str:
if char_precedence > tos_precedence: if char_precedence > tos_precedence:
stack.push(char) stack.push(char)
break break
elif char_precedence == tos_precedence: if char_precedence < tos_precedence:
postfix.append(stack.pop())
break
# Precedences are equal
if associativity(char) == "RL": if associativity(char) == "RL":
stack.push(char) stack.push(char)
break break
else:
postfix.append(stack.pop())
else:
postfix.append(stack.pop()) postfix.append(stack.pop())
while not stack.is_empty(): while not stack.is_empty():