In assignment 1 you had used the data structure called Stack to evaluate arithmetic expressions by...

50.1K

Verified Solution

Question

Programming

In assignment 1 you had used the data structure called Stack toevaluate arithmetic expressions by first converting the giveninfixed expressions to postfixed expressions, and then evaluatedthe post fixed expression.

Repeat the exercise for this assignment (assignment 2) by usingthe data structure called Binary Trees. Your output must displaythe original expression, the postfixed expression representing theBinary tree, and the evaluated result.

Please bear in mind that a given expression could result in oneof the following:

• Mismatch parentheses

• Too many operators, or too many operands in which case theexpression would not have been written properly in the firstplace

• The result is assumed to be correct.

previous assigment :

import java.util.*;class Arithmetic{  public String exp,postfixexp;  public Arithmetic(String exp){    this.exp=exp;    this.postfixexp=\"\";  }  //___________________________isBalance()__________________  public boolean isBalance(){    Stack stk = new Stack();    int i;    for(i=0;i stack = new Stack<>();     for (int i = 0; i stack=new Stack<>();     for(int i=0;i

Answer & Explanation Solved by verified expert
4.4 Ratings (651 Votes)
Algorithm Let t be the expression tree If t is not null then If tvalue is operand then Return tvalue A solvetleft B solvetright calculate applies operator tvalue on A and B and returns value Return calculateA B tvalue class Node char value Node left right    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students