ass2
ass2
h>
int prec(char c) {
if (c == '^')
return 3;
return 2;
return 1;
else
return -1;
char associativity(char c) {
if (c == '^')
return 'R';
return 'L';
string infixToPostfix(string s) {
stack<char> st;
string result;
char c = s[i];
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c
<= '9'))
result += c;
else if (c == '(')
st.push('(');
else if (c == ')') {
result += st.top();
st.pop();
st.pop();
else {
associativity(s[i]) == 'L') {
result += st.top();
st.pop();
st.push(c);
}
while (!st.empty()) {
result += st.top();
st.pop();
return result;
string infixToPrefix(string s) {
reverse(s.begin(), s.end());
if (s[i] == '(')
s[i] = ')';
s[i] = '(';
reverse(postfix.begin(), postfix.end());
return postfix;
}
void print(string s1) {
cout<<s1[i];
cout<<endl;
int main() {
string exp;
cin>>exp;
bool ans=true;
int choice;
while(ans) {
cin>>choice;
switch(choice) {
case 1:
print(infixToPostfix(exp));
break;
case 2:
print(infixToPrefix(exp));
break;
case 3:
cout<<"Exited Successfully"<<endl;
ans=false;
break;
return 0;