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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!