![]() ![]() If the character is opening round bracket ( '(' ), push it into operator's stack.Never pop out ( '(' ) or ( ')' ) whatever may be the precedence level of scanned character. If the precedence of scanned operator is less than or equal to the top most operator of operator's stack, pop the operators from operand's stack untill we find a low precedence operator than the scanned character.If the precedence of scanned operator is greater than the top most operator of operator's stack, push this operator into operand's stack.If the operator's stack is not empty, there may be following possibilites.If the character is an operator and operator's stack is empty, push operator into operators' stack.If the character is an operand, put it into output stack. ![]() Scan input string from left to right character by character.The following algorithm converts infix to postfix. Output's stack works as FIFO (First In First Out). Operator's stack works as FILO(First In Last Out). We have operator's stack, output's stack and one input string. In this case, We use the stacks to convert infix to postfix. ![]() For example, +ABĪlgorithm to convert infix to postfix expression Prefix expression consists of operators followed by operands. Postfix expression consists of operands followed by operators. Infix expression is the normal expression that consists of operands and operators. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |