Question: evaluate an Infix expression, using the below algorithm AND this input expression: 11.1 + 22.2 * 3 / ( 1.1 + 5.5 ) ALGORITHM FOR

evaluate an Infix expression, using the below algorithm AND this input expression: 11.1 + 22.2 * 3 / ( 1.1 + 5.5 )

ALGORITHM FOR EVALUATION THE INFIX EXPRESSION, USING the ArrayList OF Strings instance variable: (a void method with NO parameters)

// this is a variation of the infix eval. algorithm in the textbook

/*

declare a stack of String for the operators (use an ArrayStack, I'll call opStack)

declare a stack of Double for the operands (use a LinkedStack, I'll call valStack)

for each token in the ArrayList of strings (member variable)

if the token is an operator ("+", "-","*","/")

if opStack is empty

push token onto opStack

else if precedence(token) > precedence(top of opStack (call peek(), NOT pop))

push token onto opStack

else

while opStack isn't empty AND

precedence(token) <= precedence(top of opStack) (call peek(), NOT pop)

execute( opStack, valStack )

end while

push token onto opStack

end else

end else

else if token equals "("

push token onto opStack

else if token equals ")"

while top of opStack != "(" (peek, NOT pop)

execute(opStack, valStack)

end while

pop the opStack

else

convert the token to a Double value (if you don't know how, POST IN THE FORUM)

push the Double value onto the valStack

end else

end for loop

while( opStack isn't empty )

execute(opStack, valStack)

end while

if( valStack's size is 1 )

result = top of valStack

else

result = 0

endelse

End evaluate method

//-----------------------------------------------------------------------------

// WRITE MAIN as described on the assignment and using the following method & variable:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!