JavaAlgorithms/DataStructures/Stacks
2021-10-24 10:18:49 +03:00
..
BalancedBrackets.java Formatted with Google Java Formatter 2020-10-24 10:23:28 +00:00
DecimalToAnyUsingStack.java Formatted with Google Java Formatter 2020-10-24 10:23:28 +00:00
InfixToPostfix.java Format with google formatter 2020-10-27 11:23:46 +08:00
MaximumMinimumWindow.java Implement MinMax solution using Stack (#2482) 2021-10-04 21:02:18 +03:00
NodeStack.java Formatted with Google Java Formatter 2020-10-24 10:23:28 +00:00
README.md Update README.md of stack (#2671) 2021-10-24 10:18:49 +03:00
ReverseStack.java Add Reverse Stack (#2653) 2021-10-23 15:20:26 +03:00
StackArray.java Formatted with Google Java Formatter 2020-10-24 10:23:28 +00:00
StackArrayList.java Formatted with Google Java Formatter 2020-10-24 10:23:28 +00:00
StackOfLinkedList.java Formatted with Google Java Formatter 2020-10-24 10:23:28 +00:00

STACK

Stack is an ADT (abstract data type) that acts like a list of objects but there is a difference.

Stack works on the principle of LIFO (Last In First Out), it means that the last item added to the stack will be the first item to be removed.

Stack is based on two methods (functions)-

push(element)

It adds "element" to the top of the stack.

For example: If we have 1, 3, 5 in stack, and we call push(9),

9 will be added to last index of stack -> 1, 3, 5 , 9.

peek() or top()

It returns element at the top of the stack.

For example: If we have 1, 3, 5 in stack, and we call peek(),

5 will be returned (without removing it from the stack).

pop()

It removes the last element (i.e. top of stack) from stack.

For example: If we have 1, 3, 5 , 9 in stack, and we call pop(),

the function will return 9 and the stack will change to 1, 3, 5.