A stack is a simple data structure for storing data. In stack, the order in which the data arrives is important. A pile of books is a good example of stack. Astack is an ordered list in which insertion and deletion are done at one end, where end is called top. The last element inserted is the first one to be deleted. Hence, it is called Last in First Out (LIFO) or First in Last Out (FILO) list
In this post, we’ll see the other way of implementing Stack is by Linked List. This is continuation of the previous post about Array implementation of Stack.
In this implementation, push operation is implemented by inserting element at the beginning of the list. Pop operation is implemented by deleting the node from the beginning.
Even you can throw exception instead of printing message in case of pop operation when stack is empty.