answersLogoWhite

0

I HOPE THIS WILL HELP U OUT...

ALGO GOES LIKE THIS: Reverrse prreffiix and evalluatte iitt

reverse given prefix expression;

scan the reversed prefix expression;

for each symbol in reversed prefix

if operand then

push its value onto stack S;

if operator then {

pop operand1;

pop operand2;

compute result = operand1 op operand2;

push result back onto stack S;

}

return value at top of stack;

AND EXAMPLE IS:Prefix: */-abc-+def Reversed: fed+-cba-/*

ch action stack

f push f

e push f e

d push f e d

+ pop op1 f e

pop op2 f

calc &push f (d+e)

- pop op1 f

pop op2

calc & push ((d+e)-f)

c push ((d+e)-f) c

b push ((d+e)-f) c b

a push ((d+e)-f) c b a

- pop op1 ((d+e)-f) c b

pop op2 ((d+e)-f) c

calc & push ((d+e)-f) c (a-b)

ch action stack

/ pop op1 ((d+e)-f) c

pop op2 ((d+e)-f)

calc & push ((d+e)-f) ((a-b)/c)

* pop op1 ((d+e)-f)

pop op2

calc & push ((a-b)/c)*((d+e)-f)

User Avatar

Wiki User

14y ago

What else can I help you with?

Related Questions

Program to convert a infix expression in to postfix and prefix expression in php?

To convert an infix expression to postfix and prefix in PHP, you can implement the Shunting Yard algorithm for postfix conversion and a modified approach for prefix conversion. For postfix, you use a stack to reorder operators based on their precedence and associativity while scanning the infix expression. For prefix, you can reverse the infix expression, convert it to postfix, and then reverse the resulting postfix expression. Here’s a brief code outline for both conversions: function infixToPostfix($infix) { // Implement the Shunting Yard algorithm to convert infix to postfix } function infixToPrefix($infix) { // Reverse the infix expression // Convert to postfix using infixToPostfix // Reverse the postfix result to get prefix } You would need to handle operators, parentheses, and precedence rules within these functions.


What is prefix expression?

Example: prefix: * 2 + 3 4 infix: 2 * (3+4) postfix: 2 3 4 + *


How do you use the longest Prefix Match algorithm in C programming?

You can use the longest Prefix Match algorithm in C programming by looking up the longest standard Python package match and then converting that from Python into C or C++ to figure out how to create the equivalent.


Does countenance have a prefix in it?

No, "countenance" does not have a prefix in it. It is a standalone word that means a person's facial expression or approval.


C code for evaluation of prefix expression?

a*b*c


What does prefix min mean?

Prefix min refers to an algorithm that calculates the minimum value of a given subarray in an array. It does so by precomputing prefix sums or prefix minimums to quickly determine the minimum value in any subarray. This can be useful in various programming problems and optimizations.


What is an example word for the prefix corp?

An example word with the prefix "corp" is "corporation."


Evaluate the following prefix expression 26 - 1324?

-1298


What is prefix of spelled?

An example of a prefix for 'spell' is 'mis' for misspell.


What does the prefix with mean?

The prefix with means against. An example is withdraw.


What is an antonym prefix for the capable?

The prefix is -in, as in "incapable."


Examples of prefix?

An example would be, in the word pro-democracy, pro is a prefix.