


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A c++ program to convert infix notation to postfix notation using a stack (implemented using a linked list). The program includes a function 'infixtopostfix' that takes an infix expression as input and converts it to postfix notation. The program also includes a 'prec' function to determine the precedence of operators and a 'main' function to test the 'infixtopostfix' function.
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



using namespace std; int prec(char c) { if(c == '^') return 3; else if(c == '*' || c == '/') return 2; else if(c == '+' || c == '-') return 1; else return -1; } void infixToPostfix(string s) { std::stack
st.push('('); else if(s[i] == ')') { while(st.top() != 'N' && st.top() != '(') { char c = st.top(); st.pop(); ns += c; } if(st.top() == '(') { char c = st.top(); st.pop(); } } else{ while(st.top() != 'N' && prec(s[i]) <= prec(st.top())) { char c = st.top(); st.pop(); ns += c; } st.push(s[i]); } }