Question
Create a new class named GenericStack that specifies a type variable that provide for generics. Declare a linked list that will hold the elements in
Create a new class named GenericStack that specifies a type variable that provide for generics.
Declare a linked list that will hold the elements in the stack. Then, use the linked list to implement the methods show above.
Open the GenericStacksApp class. Then, declare a generic stack at the beginning of the main method that will store String objects.
Add code to the main method that uses the push method to add at least hree items to the stack. After each item is added, display its value at the console (use a string literal to do this). Then, use the size method to return the number of items in the stack and display that value.
Use the peek method to retrn the first item and display that item, and use the size method to return the number of items again and display that value.
Use the pop method to return each items again and display that value. Use the pop method to return each item, displaying it as it's returned, and display the number of items one more time.
Result should be as below:
Push: Apples
Push: Oranges
Push: Bananas
The stack contains 3 items
Peek: Bananas
The stack contains 3 items
Pop: Bananas
Pop: Oranges
Pop: Apples
The stack contains 0 items
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started