Question description Hassan gets a job in a software company in Hyderabad. The training period for the first three months is 20000 salary. Then incremented to 25000 salaries. Training is great but they will give you a programming task every day in three months. Hassan must finish it in the allotted time. His teammate Jocelyn gives him a task to complete the concept of Infix to Prefix Conversion for a given expression. can you help him? Functional Description: Step 1: Reverse the infix expression i.e A+B*C will become C*B+A. Note while reversing each ‘(‘ will become ‘)’ and each ‘)’ becomes ‘(‘. Step 2: Obtain the “nearly” postfix expression of the modified expression i.e CB*A+. Step 3: Reverse the postfix expression. Hence in our example prefix is +A*BC. Constraints the input should be a expressions
C Program


#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <ctype.h>

typedef char* string;

char st[1000];

int top=-1;

void push(char c){st[++top]=c;}

char pop(){return st[top--];}

char peek(){return st[top];}

int empty(){return top==-1;}

int prec(char c){

    if(c=='^') return 3;

    if(c=='*'||c=='/') return 2;

    if(c=='+'||c=='-') return 1;

    return 0;

}

string infixToPostfix(string infix){

    int n=strlen(infix);

    string r=malloc(n+1);

    int k=0;

    for(int i=0;i<n;i++){

        char c=infix[i];

        if(isalnum(c)) r[k++]=c;

        else if(c=='(') push(c);

        else if(c==')'){

            while(!empty()&&peek()!='(') r[k++]=pop();

            if(!empty()) pop();

        } else {

            while(!empty()&&prec(peek())>prec(c)) r[k++]=pop();

            push(c);

        }

    }

    while(!empty()) r[k++]=pop();

    r[k]='\0';

    return r;

}

int main(){

    char infix[1000];

    scanf("%s",infix);

    int n=strlen(infix);

    char rev[1000];

    for(int i=0;i<n;i++){

        char c=infix[n-1-i];

        if(c=='(') rev[i]=')';

        else if(c==')') rev[i]='(';

        else rev[i]=c;

    }

    rev[n]='\0';

    top=-1;

    string post=infixToPostfix(rev);

    int m=strlen(post);

    for(int i=m-1;i>=0;i--) printf("%c",post[i]);

    printf("\n");

    free(post);

    return 0;

}