Stack Data Structure
Stack Data Structure
inserted element will get popped first. In some cases, when we need to process the data which is
entered last at the beginning, we sue this stack data structure. As the stack data structure uses
LIFO feature, they become the storage structure for recursion functions. They are used in UNDO
and REDO functions in Editor as we need to UNDO last operation we have done. For instance,
Microsoft word, Adobe photoshop applications has the UNDO and REDO feature which is based
on LIFO. They are also used in Operating system functions in trace backing of operations.
Diagram 1.1 and 1.2 represents an example of Stack data structure which uses the LIFO
functionality.
Diagram 1.3
Based on the output from diagram 1.3, three numbers have been pushed into the stack
(50,10,99). Once pop method is used “s.pop( )” the last element inserted is being removed.
Therefore, the remaining element would be 10 and 50. Diagram 1.4 below shows a simple
representation of the code and output based on diagram 1.1 – 1.3.
LAST-IN-FIRST-
PUSH OUT POP
99
10
10
50
50
Diagram 1.4