Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a project for these two files as well as a driver class Main java that tests them. Postfix.java contains the methods convertTo Postfix(String infix)
Create a project for these two files as well as a driver class Main java that tests them. Postfix.java contains the methods convertTo Postfix(String infix) and evaluate Postfix(String postfix), which both need to be implemented. The driver program should be able to pass infix equations to PostFix.convertTQPostfix) which should be returned properly converted. You do not need to test to see if an incoming String is a valid infix equation (although you are free to do so if you want). Just make sure when you are testing your program that you only pass proper postfix equations as arguments. Use the variables a, b, c, d, and/or e. | Simply need to call getValue(Character c) to retrieve the proper integer value for each variable In a more in-depth project, we would be able to change what these variables stand for, but that is beyond the scope of what we are doing here As an example, running the following code in your driver program should print out abcl+ 2 String postfix PostEix.convertToPostix"a bl c"), System.out.printlo(postfix), Systemout println PostEix.evaluateRostfix(postfix) getPrecedence(char operator) returns an int indicating the precedence of the operator passed in. The higher the int returned, the higher the order of precedence of the operator isVariable(char character) returns true if the incoming character is a variable. isOperator(char chacter) returns true if the incoming character is an operator. In your driver class, the following code should print out the value '2 public class Postfix public static String convertToPostfix(String infix) Stack!nterface(); = // use a StringBuilder object rather than a String, since appending is much more efficient. // To add to the StringBuilder object 'postfix': // postfix.append (stringToAppend); StringBuilder postfix = new StringBuilder(); int length = infix. length(); for(int i 0; i implements Stack!nterfaceT> private Node topNode; public LinkedStack() topNode null; private class Node private T data; private Node next private Node (T d, Node n) data-d; next nj private T getData() return data; private Node getNextNode() return next @Override public void push (T newEntry) topNodenew Node(newEntry, topNode); topNodenew Node(newEntry, topNode); @Override public T pop() if(isEmpty)) throw new EmptyStackException); T top topNode.getData); topNodetopNode.getNextNode ); return top; @Override public T peek () if(isEmpty)) throw new EmptyStackException); return topNode.getData); @Override public boolean isEmpty() return topNodenull,; @Override public void clear() topNode = null
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