In: Computer Science
Discuss the stack data structure. What is it? How can it be used? What support exists for stacks in the Java Class Library Collections Framework? Do you think this support is easy to understand and use? Why or why not? Discuss the pros and cons of creating your own stack classes vs. using those provided by the Java Class Library Collections Framework. Make sure you take into consideration the ability to handle any kind of objects (generics).
ANSWER;
stack data structure is a linear data structure which follows a particular order in the operations which are performed. there are two types of order which stack data structure follow which are
LIFO (Last in first out )
FIFO (First in Last out )
so in stack data structure, there are basically four types of operations which are as follows:
Push: add an item in stack
Pop: remove an item in stack
Top: Returns the top element of the stack.
isEmpty : returned true if the stack is empty, else false
In Java, dynamically allocated data structures which are ArrayList,
LinkedList, Vector, Stack, HashSet, HashMap, Hashtable are
supported in Collection Framework, which mandates the common
behaviors of all the classes.
There are some pros and some cons of creating your own stack classes which suppose that you are working on an application and there are some classes which you are being used so you made custom classes and these classes can be used without any new code. But the classes which are already there are more optimized and these classes are also error proof and it can be used in any situation.