Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java program Create a stack interface Stack that uses a generic type T and has the following abstract methods: isEmpty, is Full, peek (returns T),

java programimage text in transcribed

Create a stack interface Stack that uses a generic type T and has the following abstract methods: isEmpty, is Full, peek (returns T), pop(returns T), void push(T), void clear() to clear the contents of the stack, and int size (returns the number of elements in the stack). void reverse() reverses the contents of the stack (in your implementation you can use an additional local stack in your method to help you with the reverse operation.) void display() prints out the contents of the stack Write your two stack implementations (ArrayStack and ListStack) using the stack interface. Your stack implementations must have all instance variables as private. Both implementations must a constructor that initializes the capacity of the stack. For the ListStack, the stack is full when the size reaches the initial capacity. You must also implement public String toString() in both classes. It returns a String representation of the stack contents. Create a simple main class QuestionOne that creates two stacks of Integers of capacity = 20 one that uses the ArrayStack and the other uses the ListStack implementations. Push 20 values in each: in the first (1, 2, 3, ..., 20) and in the second (20, 19, .., 13, ..., l). Call the following methods for both stacks in the given order: display, reverse, display, peek, pop, pop, reverse, size, isFull, isEmpty, display, clear, display, isEmpty

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

Students also viewed these Databases questions