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,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())
continue
# 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():