We all know about Stack data structure, right? For those of you who do not know, Stack is a data structure which is used to store data in a structured way.
In a Stack, data which is stored at the end, is the data which is removed first. This is behavious of Stack is also known as Last in First Out or First in Last Out.
A stack data structure generally has the following 3 methods:
push(): For adding data to the stack.
pop(): For removing data from the stack.
size(): To check the size of stack.
isEmpty(): To check if the stack is empty or not.
A few other points to remember are:
You cannot add or remove data randomly from a Stack.
The addition and removal of data elements happen from a single side.
So let's write a simple class
Stack to implement stack in python.