(Solved) : Would Really Appreciate Help Problem S Giving Trouble Two Stacks Size Elements Correspondi Q42777142 . . .

Would really appreciate help on this problem, it’s been givingme some trouble.

Two stacks are the same if they have the same size and theirelements at the corresponding positions are the same. Add themethod equalStack to Class StackClass that takes as a parameter aStackClass object, say otherStack and return true if the stack isthe same as otherStack. Also write the definition of methodequalStack and a program to test your method. In StackClass.java,please finish method – public boolean equalStack(StackClassotherStack) and testing main program – StackProblem.java.

******************************************************************************************************************************************************************************

public class StackProblem {

public static void main(String[] args) {

StackClass intStack = new StackClass(50);

StackClass tempStack = new StackClass(50);

}

}

******************************************************************************************************************************************************************************

public class StackUnderflowException extends StackException{

public StackUnderflowException() {

super(“Stack Underflow”);

}

public StackUnderflowException(String msg) {

super(msg);

}

}

******************************************************************************************************************************************************************************

public interface StackADT<T> {

public void initializeStack();

public boolean isEmptyStack();

public boolean isFullStack();

public void push(T newItem) throws StackOverflowException;

public T peek() throws StackUnderflowException;

public void pop() throws StackUnderflowException;

}

******************************************************************************************************************************************************************************

public class StackClass implements StackADT {

private int maxStackSize;

private int stackTop;

private T[] list;

public StackClass() {

maxStackSize = 100;

stackTop = 0;

list = (T[]) new Object[maxStackSize];

}

public StackClass(int stackSize) {

if (stackSize <= 0) {

System.err.println(“The size of the array to ” + “implement thestack must be ” + “positive.”);

System.err.println(“Creating an array of size 100.”);

maxStackSize = 100;

}

else

maxStackSize = stackSize;

stackTop = 0;

list = (T[]) new Object[maxStackSize];

}

public void initializeStack() {

for (int i = 0; i < stackTop; i++)

list[i] = null;

stackTop = 0;

}

public boolean isEmptyStack() {

return (stackTop == 0);

}

public boolean isFullStack() {

return (stackTop == maxStackSize);

}

public void push(T newItem) throws StackOverflowException {

if (isFullStack())

throw new StackOverflowException();

list[stackTop] = newItem;

stackTop++;

}

public T peek() throws StackUnderflowException {

if (isEmptyStack())

throw new StackUnderflowException();

return (T) list[stackTop – 1];

}

public void pop() throws StackUnderflowException {

if (isEmptyStack())

throw new StackUnderflowException();

stackTop–;

list[stackTop] = null;

}

public boolean equalStack(StackClass otherStack) {

boolean isEqual = true;

}

Expert Answer


Answer to Would really appreciate help on this problem, it’s been giving me some trouble. Two stacks are the same if they have the…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us

× How can I help you?