Question
In Java, and also it can be an array or reference based code. Both of those are attached with all pseudo code, Interface and exception
In Java, and also it can be an array or reference based code. Both of those are attached with all pseudo code, Interface and exception file for java.
//StackInterface.java
public interface StackInterface { public boolean isEmpty(); // Determines whether the stack is empty. // Precondition: None. // Postcondition: Returns true if the stack is empty; // otherwise returns false.
public void popAll(); // Removes all the items from the stack. // Precondition: None. // Postcondition: Stack is empty.
public void push(Object newItem) throws StackException; // Adds an item to the top of a stack. // Precondition: newItem is the item to be added. // Postcondition: If insertion is successful, newItem // is on the top of the stack. // Exception: Some implementations may throw // StackException when newItem cannot be placed on // the stack.
public Object pop() throws StackException; // Removes the top of a stack. // Precondition: None. // Postcondition: If the stack is not empty, the item // that was added most recently is removed from the // stack and returned. // Exception: Throws StackException if the stack is // empty. public Object peek() throws StackException; // Retrieves the top of a stack. // Precondition: None. // Postcondition: If the stack is not empty, the item // that was added most recently is returned. The // stack is unchanged. // Exception: Throws StackException if the stack is // empty. } // end StackInterface
//StackException.java
public class StackException extends java.lang.RuntimeException {
public StackException(String s) {
super(s);
} // end constructor
private final static long serialVersionUID = 2006L;
} // end StackException
//StackArrayBased.java
public class StackArrayBased implements StackInterface { final int MAX_STACK = 50; // maximum size of stack private Object items[]; private int top;
public StackArrayBased() { items = new Object[MAX_STACK]; top = -1; } // end default constructor
public boolean isEmpty() { return top
public boolean isFull() { return top == MAX_STACK-1; } // end isFull
public void push(Object newItem) throws StackException { if (!isFull()) { items[++top] = newItem; } else { throw new StackException("StackException on " + "push: stack full"); } // end if } // end push
public void popAll() { items = new Object[MAX_STACK]; top = -1; } // end popAll public Object pop() throws StackException { if (!isEmpty()) { return items[top--]; } else { throw new StackException("StackException on " + "pop: stack empty"); } // end if } // end pop
public Object peek() throws StackException { if (!isEmpty()) { return items[top]; } else { throw new StackException("Stack exception on " + "peek - stack empty"); } // end if } // end peek } // end StackArrayBased
//StackReferenceBase.java
public class StackReferenceBased implements StackInterface { private Node top;
public StackReferenceBased() { top = null; } // end default constructor public boolean isEmpty() { return top == null; } // end isEmpty
public void push(Object newItem) { top = new Node(newItem, top); } // end push public Object pop() throws StackException { if (!isEmpty()) { Node temp = top; top = top.getNext(); return temp.getItem(); } else { throw new StackException("StackException on " + "pop: stack empty"); } // end if } // end pop public void popAll() { top = null; } // end popAll public Object peek() throws StackException { if (!isEmpty()) { return top.getItem(); } else { throw new StackException("StackException on " + "peek: stack empty"); } // end if } // end peek } // end StackReferenceBased
Assignment Objective Your goal will be to convert an infix expression to a postfix expression and evaluate the postfix expression using a stack to implement Dijkstra's Shunting Algorithm, which can be found in Introduction to Stacks Part 4 PDEpdf Implementation Details You can use the textbook implementation of these files . Stacklnterface,java . StackException,java StackArrayBased.javaor StackReferenceBased.java Your code should include comments and documentation, as well as preconditions and postconditions. Testing Here is the procedure for testing, which must be documented (a Word document is preferred, as is the use of screenshots). Convert the following infix expressions to postfix, display the postfix expression, and evaluate the postfix expression. (2+4) (6-9) 2+3*(4+5)/3 Assignment Objective Your goal will be to convert an infix expression to a postfix expression and evaluate the postfix expression using a stack to implement Dijkstra's Shunting Algorithm, which can be found in Introduction to Stacks Part 4 PDEpdf Implementation Details You can use the textbook implementation of these files . Stacklnterface,java . StackException,java StackArrayBased.javaor StackReferenceBased.java Your code should include comments and documentation, as well as preconditions and postconditions. Testing Here is the procedure for testing, which must be documented (a Word document is preferred, as is the use of screenshots). Convert the following infix expressions to postfix, display the postfix expression, and evaluate the postfix expression. (2+4) (6-9) 2+3*(4+5)/3Step 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