Question: Infix to postfix implementation in C using stacks, assuming stacks is already implemented -create an empty stack and an empty string for the output -scan

Infix to postfix implementation in C using stacks, assuming stacks is already implemented

-create an empty stack and an empty string for the output

-scan each token in the input string from left to right

-if the current token is an operand, append it to the output string

-if the current token is a left (, push it on the stack

-if the current token is right ), keep pooping from the stack until the left ( is returned, append each popped operator to the output string

-if the current token is an operator, if the precedence of second operator is greater than the first, pop the 2nd operator and append to the output string. Then push the first operator to the stack.

-when input string is processed, pop all the remaining operators and append to the output string

-return output string

======================================================================

char* charToString(char c) { char *str = (char*)malloc(sizeof(char)*2); str[0] = c; str[1] = '\0'; return str; } char stringToChar(char* str) { return str[0]; }

char* intToString(int res) { char *str = (char*)malloc(BUFSIZ); sprintf(str,"%d",res); return str; }

int stringToInt(char* str) { return atoi(str); }

int precedence(char x) { return -1; }

char* convertToPostFix(char* str) { char* postfix = " ";

//todo

return postfix; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!