[PR #910] [CLOSED] Stack to carry out infix to postfix conversion. #1439

Open
opened 2026-01-29 15:20:41 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/TheAlgorithms/C/pull/910
Author: @shrijalshr
Created: 10/31/2021
Status: Closed

Base: masterHead: patch-1


📝 Commits (1)

  • 35c2457 Stack to carry out infix to postfix conversion.

📊 Changes

1 file changed (+105 additions, -0 deletions)

View changed files

data_structures/stack/infix_postfix_conversion.c (+105 -0)

📄 Description

Implementation of stack to carry out infix to postfix conversion.
Theory:
The Polish Mathematician Han Lukasiewicz suggested a notation called Polish
notation, which gives two alternatives to represent an arithmetic expression,
namely the postfix and prefix notations. In postfix notation, the operator is written
after the two operands. The advantage of the postfix notation (also called reverse
polish notation) are:

  1. The need for parenthesis as in an infix expression is overcome in postfix and
    prefix notations.
  2. The priority of operators is no longer relevant.
  3. The order of evaluation depends on the position of the operator but not on
    priority and associativity.
    Algorithm to convert infix expression to postfix:
  4. Scan the infix expression from left to right.
  5. If the scanned character is an operand, output it.
  6. Else,
    3.1 If the ICP>ISP or the stack is empty, push it.
    3.2 Else, pop the operator from the stack until ICP<=ISP. Push the scanned
    operator to the stack.
  7. If the scanned character is an “(“push it onto the stack.
  8. If the scanned character is an “)”, pop and output from the stack until an “(” is
    encountered.
  9. Repeat steps 2-6 until the infix expression is totally scanned.
  10. Pop and output from the stack until it is not empty

Description of Change

Implementation of stack to carry out infix to postfix conversion.

References

Checklist

  • [ x] Added description of change
  • [ x] Relevant documentation/comments is changed or added
  • [x ] PR title follows semantic commit guidelines
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

Implementation of stack to carry out infix to postfix conversion.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/TheAlgorithms/C/pull/910 **Author:** [@shrijalshr](https://github.com/shrijalshr) **Created:** 10/31/2021 **Status:** ❌ Closed **Base:** `master` ← **Head:** `patch-1` --- ### 📝 Commits (1) - [`35c2457`](https://github.com/TheAlgorithms/C/commit/35c2457dfb4b0ed4059863ece4cf6d647cbfcea0) Stack to carry out infix to postfix conversion. ### 📊 Changes **1 file changed** (+105 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `data_structures/stack/infix_postfix_conversion.c` (+105 -0) </details> ### 📄 Description Implementation of stack to carry out infix to postfix conversion. Theory: The Polish Mathematician Han Lukasiewicz suggested a notation called Polish notation, which gives two alternatives to represent an arithmetic expression, namely the postfix and prefix notations. In postfix notation, the operator is written after the two operands. The advantage of the postfix notation (also called reverse polish notation) are: 1. The need for parenthesis as in an infix expression is overcome in postfix and prefix notations. 2. The priority of operators is no longer relevant. 3. The order of evaluation depends on the position of the operator but not on priority and associativity. Algorithm to convert infix expression to postfix: 1. Scan the infix expression from left to right. 2. If the scanned character is an operand, output it. 3. Else, 3.1 If the ICP>ISP or the stack is empty, push it. 3.2 Else, pop the operator from the stack until ICP<=ISP. Push the scanned operator to the stack. 4. If the scanned character is an “(“push it onto the stack. 5. If the scanned character is an “)”, pop and output from the stack until an “(” is encountered. 6. Repeat steps 2-6 until the infix expression is totally scanned. 7. Pop and output from the stack until it is not empty #### Description of Change Implementation of stack to carry out infix to postfix conversion. <!-- Thank you for your Pull Request. Please provide a description above and review the requirements below. Added an implementation of algorithm to carry out infix to postfix conversion in C. Contributors guide: https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md --> #### References <!-- Add any reference to previous pull-request or issue --> #### Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [ x] Added description of change - [ x] Relevant documentation/comments is changed or added - [x ] PR title follows semantic [commit guidelines](https://github.com/TheAlgorithms/C/blob/master/CONTRIBUTING.md#Commit-Guidelines) - [x] I acknowledge that all my contributions will be made under the project's license. Notes: <!-- Please add a one-line description for developers or pull request viewers --> Implementation of stack to carry out infix to postfix conversion. <a href="https://gitpod.io/#https://github.com/TheAlgorithms/C/pull/910"><img src="https://gitpod.io/button/open-in-gitpod.svg"/></a> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 15:20:41 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/C#1439