Stack

                           
 

         Stack a data structure finds very interesting application in real world. Stack which is just like a pile of books where insertion and deletion happens at one end (i.e) at the top.One can even have a look on the top element (i.e) peek.Stack stands for LIFO (Last In First Out).Stack is a static data type where the size of the stack is initialized first before any operation. The operations which can be done on stack are PUSH - inserting an element on top ,  POP- to delete the top element , PEEK - to look on the top element and check whether ISEMPTY or ISFULL .Some of it applications are:
                                              
                                                1. Reversal
                                                2. Postponement
                                                3. Backtracking
                                                4. Expression evaluation
                                                5. Expression conversion
                                                       a. Infix to postfix
                                                       b. Infix to prefix
                                                       c. Postfix to infix
                                                       d. Prefix to infix
Procedure for postfix conversion :
1.Scan the Infix string from left to right.
2.Initialize an empty stack.
3.If the scanned character is an operand, add it to the Postfix string.
4.If the scanned character is an operator and if the stack is empty push the character to stack.
5.If the scanned character is an Operator and the stack is not empty, compare the precedence of the character with the element on top of the stack.
6.If top Stack has higher precedence over the scanned character pop the stack else push the scanned character to stack. Repeat this step until the stack is not empty and top Stack has precedence over the character.
7.Repeat 4 and 5 steps till all the characters are scanned.
8.
After all characters are scanned, we have to add any character that the stack may have to the Postfix string.
9.If stack is not empty add top Stack to Postfix string and Pop the stack.
10. Repeat this step as long as stack is not empty.
Previous
Next Post »