Question: public class StackArray implements StackInterface { private int capacity; private int top; private T [ ] stackArray; public StackArray ( int capacity ) { this.capacity
public class StackArray implements StackInterface
private int capacity;
private int top;
private T stackArray;
public StackArrayint capacity
this.capacity capacity;
this.top ;
this.stackArray T new Objectcapacity;
public void pushT item
if isFull
throw new RuntimeExceptionStack is full";
stackArraytop item;
public T pop
if isEmpty
System.out.printlnunable to pop, stack is empty";
return null;
T itemOnTop stackArraytop;
stackArraytop null;
top;
return itemOnTop;
public T peek
if isEmpty
System.out.printlnunable to peek, stack is empty";
return null;
return stackArraytop;
public boolean isEmpty
return top ;
public int size
return top ;
public boolean containsT item
for int i ; i top; i
if stackArrayiequalsitem
return true;
return false;
public void print
if isEmpty
System.out.printlnStack is empty";
else
System.out.printStack: ;
for int i top; i ; i
System.out.printstackArrayi;
System.out.println;
public int capacity
return capacity;
public boolean isFull
return top capacity ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
