Compare commits

..

2 Commits

Author SHA1 Message Date
AmirSoroush
5b760f06f8
Update data_structures/stacks/infix_to_postfix_conversion.py
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
2023-07-31 23:07:22 +03:00
AmirSoroush
78e9dc4c7a
Update data_structures/stacks/infix_to_postfix_conversion.py
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
2023-07-31 22:53:42 +03:00

View File

@ -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())
continue
# Precedences are equal
if associativity(char) == "RL":
stack.push(char)
break
postfix.append(stack.pop())
while not stack.is_empty():
postfix.append(stack.pop())