Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
amirsoroush opened this issue Apr 19, 2023 · 2 comments · Fixed by #8674
Labels

Comments

@amirsoroush
Copy link
Contributor

amirsoroush commented Apr 19, 2023

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.

amirsoroush added a commit to amirsoroush/PythonAlgorithms that referenced this issue Apr 19, 2023
@saddam-94
Copy link

Hi @amirsoroush, does it still available to fix? I would like to work on this issue. Could you please assign me in it? Thank you.

@amirsoroush
Copy link
Contributor Author

@h-muhammed Hi. Actually I fixed it by this PR but it hasn't reviewed by the maintainers yet. I would be glad if you review it.

tianyizheng02 added a commit that referenced this issue Aug 1, 2023
#8674)

* fixes #8673; Add operator's associativity check for stacks/infix_to_postfix_conversion.py

* fix ruff N806 in stacks/infix_to_postfix_conversion.py

* Update data_structures/stacks/infix_to_postfix_conversion.py

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

* Update data_structures/stacks/infix_to_postfix_conversion.py

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

---------

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
sedatguzelsemme pushed a commit to sedatguzelsemme/Python that referenced this issue Sep 15, 2024
…ks/infix_to_p… (TheAlgorithms#8674)

* fixes TheAlgorithms#8673; Add operator's associativity check for stacks/infix_to_postfix_conversion.py

* fix ruff N806 in stacks/infix_to_postfix_conversion.py

* Update data_structures/stacks/infix_to_postfix_conversion.py

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

* Update data_structures/stacks/infix_to_postfix_conversion.py

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

---------

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
@isidroas isidroas mentioned this issue Jan 25, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants