Answered step by step
Verified Expert Solution
Question
1 Approved Answer
No Output show in after running this what is wrong? import java.util.Scanner; interface StackInterface { void push ( T entry ) ; T pop (
No Output show in after running this what is wrong?
import java.util.Scanner;
interface StackInterface
void pushT entry;
T pop;
T peek;
boolean isEmpty;
void clear;
class LinkedStack implements StackInterface
private Node topNode;
public LinkedStack
topNode null;
public void pushT newEntry
Node newNode new NodenewEntry topNode;
topNode newNode;
public T pop
T top peek;
if topNode null
topNode topNode.getNextNode;
return top;
public T peek
if isEmpty
throw new IllegalStateExceptionStack is empty";
return topNode.getData;
public boolean isEmpty
return topNode null;
public void clear
topNode null;
private class Node
private T data;
private Node next;
private NodeT dataPortion
thisdataPortion null;
private NodeT dataPortion, Node nextNode
data dataPortion;
next nextNode;
private T getData
return data;
private Node getNextNode
return next;
class ArrayStack implements StackInterface
private T stack;
private int topIndex;
private static final int DEFAULTCAPACITY ;
private static final int MAXCAPACITY ;
public ArrayStack
thisDEFAULTCAPACITY;
public ArrayStackint initialCapacity
@SuppressWarningsunchecked
T tempStack T new ObjectinitialCapacity;
stack tempStack;
topIndex ;
public void pushT newEntry
ensureCapacity;
topIndex;
stacktopIndex newEntry;
public T pop
if isEmpty
throw new IllegalStateExceptionStack is empty";
T top stacktopIndex;
stacktopIndex null;
topIndex;
return top;
public T peek
if isEmpty
throw new IllegalStateExceptionStack is empty";
return stacktopIndex;
public boolean isEmpty
return topIndex ;
public void clear
while isEmpty
pop;
private void ensureCapacity
if topIndex stack.length
int newLength stack.length;
ensureCapacitynewLength;
private void ensureCapacityint newLength
if newLength MAXCAPACITY
throw new IllegalStateExceptionAttempt to create a stack
"whose capacity exceeds
"allowed maximum of MAXCAPACITY;
stack java.util.Arrays.copyOfstack newLength;
public class StackMath
public static void mainString args
Scanner scanner new ScannerSystemin;
System.out.printlnEnter an infix or postfix expression:";
String expression scanner.nextLinetrim;
System.out.printlnInfix: postfixinfixexpression;
System.out.printlnPostfix: infixpostfixexpression;
System.out.printlnEvaluation infix: evaluateInfixexpression;
System.out.printlnEvaluation postfix: evaluatePostfixexpression;
public static String infixpostfixString infix
Implement conversion from infix to postfix
return ;
public static String postfixinfixString postfix
Implement conversion from postfix to infix
return ;
public static int evaluatePostfixString postfix
Implement evaluation of postfix expression
return ;
public static int evaluateInfixString infix
Implement evaluation of infix expression
return ;
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