Skip to content

Need to support for unary operator in postfix evaluation. #8754

Closed
@amirsoroush

Description

@amirsoroush

Feature description

As mentioned in #8724, we have two files for evaluating postfix expressions. But currently both of them only work with binary operators and will raise an exception when an unary operator is given.

example:

>>> res = evaluate_postfix(["2", "-", "3", "+"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../stacks/evaluate_postfix_notations.py", line 31, in evaluate_postfix
    b, a = stack.pop(), stack.pop()
IndexError: pop from empty list
>>> 

2-3+ is a postfix notation for -2+3 infix and should result in 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis PR modified some existing files

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions