Stack: LIFO - Last In First Out
The 4 major operations in Stack are:
1. isEmpty: To check whether the stack is empty or not
2. push: To push the element at the top of the stack
3. pop: To remove the top most element from the stack
4. seek : To see which element is present in the top
There are 3 ways to implement stack in java:
Implementing the stack from arrays has a disadvantage of fixed size. So mostly Array list and Linked list are preferred.In Java, Most of the data Structures are implemented using Collections framework. In coding competitions and other online things we use this framework which provides us the basic template of the stack implementation so we just use the methods and write the code according to our needs.
Implementing stack from Array List:
https://stacksbycaptainuchiha.blogspot.com/2022/12/implementing-stack-using-linked-list.html
Comments
Post a Comment