Bapuji Vaditya Nayak

Bapuji Vaditya Nayak
Writer

Thursday, August 26, 2010

Stack - What, How, Why, Where?

I am a data structure
I hold elements from bottom to top
You can see me in a tray of idli plates
So I am a linear data structure
And so my name is called stack

Elements are inserted in me at the top
From the same top elements are deleted
So elements are removed in the reverse
Order that they have been inserted
And so I am well known for LIFO operation


Let me introduce you my terminology
Pointer TOP keeps track of the top element
PUSH inserts an element and POP deletes
OVERFLOW occurs if pushed when I am full
UNDERFLOW occurs if popped when I am empty


Let me tell you how I am implemented
With arrays or linked lists I can be created
At the beginning I am empty implies top = -1
Before pushing see whether I am overflowing
For each push an element is inserted in me implies top++
Before popping see whether I am under flowing
For each pop an element is taken out from me implies top--


Let me tell you where I am used
To know the history of web pages visited
To undo sequence in a text editor
To evaluate a postfix expression
To return from function calls and
To all uses where LIFO is required

                     Bapuji Vaditya Nayak
                     Senior Teaching Faculty
                     Department of Technical Education
                     Government of Andhra Pradesh
                     vadityabapu@gmail.com 9440076244

4 comments: