Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started