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
Get step-by-step solutions from verified subject matter experts
