Question: Write 2 implementations of the class Stack. Each such class should have the name Stack but they should be placed in different packages. The first

Write 2 implementations of the class Stack. Each such class should have the name "Stack" but they should be placed in different packages.

The first implementation can be taken from the previous excercise and can be in a package "tables" (

tables.Stack

).

The second (

lists.Stack

) can be based on lists (as a skeleton below) .

Remeber to use "public" ad "private" modifiers where necessary.

Then, write a program using stacks and being able to work with both implementations with the same interface. Verify if it is so by choosing the implementation by "import tables.Stack;" or "import lists.Stack;".

package lists; class StackElem { int data; StackElem next; } public class Stack { private StackElem last=null; public void push (int i) { ...} public void pop () { last = last.next; } ... }

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!