Skip to content

There is a missing check for the "associativity" of the operators in the stacks/infix_to_postfix_conversion.py file. #8673

Closed
@amirsoroush

Description

@amirsoroush

Repository commit

1158294

Python version (python --version)

Python 3.10.6

Dependencies version (pip freeze)

astroid==2.11.3
bcc==0.18.0
black==22.3.0
blinker==1.4
Brlapi==0.8.3
certifi==2020.6.20
chardet==4.0.0

Expected behavior

Hi, In the data_structures/stacks/infix_to_postfix_conversion.py file, when we pass "2^3^2" argument to the infix_to_postfix function, it should return '2 3 2 ^ ^' back. This results in number 512 which is the correct calculation.

Actual behavior

Currently infix_to_postfix("2^3^2") returns '2 3 ^ 2 ^' which is wrong. If we calculate it, it returns number 64.

The reason behind this is that currently we don't have any check for the "associativity" of the operators. In particular ^ operator causes problem here. It has Right-To-Left associativity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions