Question: Q:1. A) Implement a stack and conversion from infix to prefix conversion algorithm (given below) in C language. (20 pts) Hint: 1. Use #include and

 Q:1. A) Implement a stack and conversion from infix to prefix

Q:1. A) Implement a stack and conversion from infix to prefix conversion algorithm (given below) in C language. (20 pts) Hint: 1. Use #include and strrev(str) function which reverses a given input string str 2. Implement the precedence function using the table below Precedence: Operator Symbol Precedence priority) Exponential 1 (highest) Multiplication Division, Left * 4( 2 Paranthesis Addition, Subtraction +, 3 (lowest) Create an empty prefix string Reverse given input infix string Create an empty operator stack S For each symbol ch in the reversed infix string do {if ch is an operand then append it to the output prefix string; else if ch=") then push ch onto operator stack S else if ch="(then pop and append operators to output prefix string until the matching )' is encountered //(discared the two parenthesis) else //ch is some other operator {while operator stack is not empty and precedence(top(S))> precedence(ch) and top(S)!=') Il you should implement the precedence function {pop operator Stack and append the popped character to the output prefix string }//end while Push(ch);/push the character to operator stack S }//end else }// end for While operator stack S is not empty {pop operator Stack and append the popped character to the output prefix string Reverse the output infix string and print result

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!