conversion from infix to prefix

后端 未结 14 1321
有刺的猬
有刺的猬 2020-12-09 10:24

I am preparing for an exam where i couldn\'t understand the convertion of infix notation to polish notation for the below expression:

(a–b)/c*(d + e – f / g)         


        
14条回答
  •  再見小時候
    2020-12-09 10:52

    This is the algorithm using stack.
    Just follow these simple steps.

    1.Reverse the given infix expression.

    2.Replace '(' with ')' and ')' with '(' in the reversed expression.

    3.Now apply standard infix to postfix subroutine.

    4.Reverse the founded postfix expression, this will give required prefix expression.

    In case you find step 3 difficult consult http://scanftree.com/Data_Structure/infix-to-prefix where a worked out example is also given.

提交回复
热议问题