Create a new class named genericstack that specifies a type


Create a class called GenericStack that uses a linked list to implement a stack, which is a collection that lets you access entries on a first-in, last-out basis. Then you'll create another class that uses the GenericStack class.

The GenericStack class should implement these methods.

Push(element): Adds an element to the top of the stack.
Pop(): Returns and removes the element at the top of the stack
Peek():Returns but does not remove the element at the top of the stack.
Size(): Returns the number of entries in the stack.

A. Create a GenericStack class

i. Create a new class named GenericStack that specifies a type variable that provides for generics.

ii. Declare a linked list that will hold the elements in the stack. Then, use the linked list to implement the methods listed above.

B.. Create a class that uses GenericStack class

i. Open the GenericStackApp class. Then declare a generic stack at the beginning of the main method that will store-String objects.

ii. Add code to the main method that uses the push method to add at least 3 items to the stack. After each item is added, display its value at the console. Then use the size method to return the number of items in the stack and display that value

iii. Use the peek method to return the first item and display that item and use the size method to return the number of items again and display that value

iv.Use the pop method to return each item, displaying it as its returned and display the number of items one more time.

v. Output will be as follows:

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.

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Create a new class named genericstack that specifies a type
Reference No:- TGS01668808

Now Priced at $40 (50% Discount)

Recommended (96%)

Rated (4.8/5)