Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions