|
Stacks->Applications |
|||||
| As I already said
- Stacks help computers in unfolding their recursive jobs; used in
converting an expression to its postfix form; used in Graphs to find
their traversals (we have seen that); helps in non-recursive traversal
of binary trees (we'll see this) and so on....
Well, we'll see here, its role in converting an infix to a postfix expression. The rest of them I've some how covered in other parts of my tutorial. So here we go.... An INFIX expression is nothing but any regular expression having operators in between operands; and obviously, the POSTFIX is the one with operands followed by their respective operators. I'll take an example... If a/b-c*d is your infix expression then ab/cd*- will be its postfix form. How ?...Let's see. First step is to apply brackets to the expression following the BODMAS rule; then just move the operators to their respective closing brackets. The resultant is your Postfix expression. Remember, this is the manual way of doing it.
Now, where does Stack figure out in between? Well, when the computer has to do this conversion, it makes use of Stack. See how.. Algorithm:- C implementation:- Note:- I have deliberately hidden lot many implementation details like - stack details, push-pop operations; how to check for an OPERAND; how to set priority for the operators; bottom of the stack should have the least priority, etc. Please, try to fill up these gaps, believe me its really very interesting or else download the complete implementation and carefully study it. Related Operations: |
|||||
| Index || Doubts / Clarifications || Related Topics || Web Links | |||||