C++ Program To Convert Infix To Postfix Expression Using Stack














































C++ Program To Convert Infix To Postfix Expression Using Stack



Description:

Infix expression:The expression of the form a op b. When an operator is in-between every pair of operands.

Postfix expression:The expression of the form a b op. When an operator is followed for every pair of operands.

To convert Infix to Postfix, The variables are passed directly to Postfix and operands are passed to Stack.If ) is encounterd, Stack is popped and element is passed to Postix Expression

Code:

#include<iostream> #include<stack> using namespace std; void Postfix(char *a) { stack <char> s; char output[50],t; for(int i=0;a[i]!='\0';i++) { char ch = a[i]; switch(ch) { case '^': case '-': case '+': case '/': case '*': s.push(ch); break; case ')': t=s.top(); s.pop(); cout<<t; break; } if (isalpha(ch)) cout<<ch; } } int main() { char a[] = "(((a*b)+(c/d))-e)"; Postfix(a); return 0; }

Output:



More Articles of Avikrit Kohli:

Name Views Likes
C++ Program To Implement Simpsons 3/8th rule 360 2
C++ Program To Reverse String Without Using String Functions 381 20
C++ Program To Reverse Line In Text File 1243 1
C++ Program To Reverse Each Word In Text File 324 1
C++ Program To Read Text File Word By Word 1428 1
C++ Program To Create And Display Text File 303 1
C++ Program To Find Root Using Newton-Raphson Method 5394 11
C++ Program To Find Root Using Bisection Method 1125 1
C++ Program For Cohen Sutherland Clipping Algorithm 1839 1
To Sort Array Of Integers Using Bubble,Insertion And Selection Sort 317 1
C++ Program To Delete Element In Array At Particular Position 517 1
C++ Program To Insert Element In Array At Given Position 698 1
C++ Program To Implement Stack Using Arrays 331 1
Python Program To Add Source Code of A Webpage 239 1
Python Program To Extract Data From Excel 267 1
C++ Program To Find Sum Of Fibonacci Series Using Recursion 459 1
Program To Display Level Order Transversal Using Queue 254 1
C++ Program To Find The Minimum In Subarray Of Size k Using Deque 267 1
C++ Program To Sort Stack Recursively 857 1
C++ Program To Reverse Stack Recursively 262 1
C++ Program To Insert At Bottom Of Stack Using Recursion 266 1
C++ Program To Create Tower Of Hanoi 2427 1
C++ Program To Convert Infix To Postfix Expression Using Stack 10945 3
C++ Program To Balance Parenthesis Using Stack 963 1
C++ Program To Implement Queue Using Array 2256 2
C++ Program To Sort Two Arrays And Inserting Result In Third array 258 1
C++ Program To Find Length Of Linked List 675 1
C++ Program To Search An Element Recursively In Linked List 293 1
C++ Program To Reverse Linked List Recursively 1153 1
To Find Negation of Number Using Operator Overloading 241 1
C++ Program to create Hangman 2639 1
C++ Program to Swap two numbers without using third variable 318 2

Comments