Stack implementation in Java using array

By | June 15, 2020

Stack is a linear data structure which follows the LIFO(Last In First Out) principle. That means the Item can be inserted or removed only from top of the stack.

Stack has mainly three basic operations and few of are auxiliary operations like isEmpty,size,isFull etc:

  • Push:¬†Adding an item into the top of stack. If the stack is full then this condition is said to be an Overflow condition.
  • Pop:Removing an item from the top of stack. If the stack is empty, then thus condition is said to be an Underflow condition.
  • Peek or Top:Returns top element of stack.

 

Client program which using Stack:

 

output of the program:

 true
false
50
50
4

You May Also Like:

How to implement LRU Cache in Java?
What will happen if in a try block we throw an exception but in the finally block we return a int value?
Adding two numbers without using arithmetic operators?

Thanks for visiting the blog. If you have any doubts or suggestions to make please drop a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *