In: Computer Science
The stack is a linear data structure that is used to stores the collection of objects and it follows LIFO. But if you want to store more data you can use the dynamic stack, it is a stack data structure whose length and capacity (max no. of elements can be stored) increases /decreases in real-time based on operations like insertion, deletion,..etc performed on it.
A stack can be implemented by an array but since we are using an array to implement we cannot insert elements more than the size of the array, if we do it'll throw an error "memory overflow" because the size of the array is fixed and that's a problem there. To overcome this problem we use stack dynamic.
To make a stack dynamic we implement stack using LinkedList such stack is called dynamic stack.
How to implement dynamic stack array?
Implementation of dynamic stack:
Save this as Stack.java
Now save this as DynamicStackTest.java
To compile the program:
javac -d .Stack.java
javac -d .DynamicStackTest.java
and to run:
java ClassIllustration.DynamicStackTest
OUTPUT: