Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

7. ( 5 points) The following function converts a prefix expression to an infix expression assuming the expression can only contain unsigned integer numbers and

image text in transcribed
7. ( 5 points) The following function converts a prefix expression to an infix expression assuming the expression can only contain unsigned integer numbers and " + " and " - " operators. public static String convert(String prefix) | stack s - new AStack: String operandi, operand2, infixi int i= prefix. length -1 : while (i>=0) ( char nextc = prefix.charAt (i); if ( (nextc =="+") (nextc ==+1) operandl =spop(); operand 2=spop(); inf 1x=1(+ operand 1+ nextc + operand 2+"); s.push (infix); i--; I else if (Character. isDigit (nextc)) i int end = i; while (Character. isDigit (prefix.charAt (i)) im; infix = prefix.substring (i+1, end +1); s. push (infix); ? else i; 1 return s.pop (); 1 (a) (2.5 points) Rewrite only the lines of code that need to be changed so that the above function converts a prefix expression to a postfix expression. r (b) (2.5 points) Describe in words what changes are needed on the above given convert () function so that it also finds the value of the converted prefix expression

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions