Expression is a string of operands and operators. Operands are some numeric values and operators are of two types: Unary operators and Binary operators. Unary operators are '+' and '-' and binary operators are '+', '-', '*', '/' and exponential. In general, there are three types of expressions
Expression
Expression
is a string of operands and operators. Operands are some numeric values and
operators are of two types: Unary operators and Binary operators. Unary
operators are '+' and '-' and binary operators are '+', '-', '*', '/' and
exponential. In general, there are three types of expressions:
1.
Infix expression 2. Postfix expression 3. Prefix expression.
One
of the application of stack is conversion of expression. First of all, let us
see these expressions with the help of examples :
1. Infix Expression :
In
this type of expressions the arrangement of operands and operator is as
follows:
Infix
expression = operand1 operator operand2
For
example
1.
(a+b)
2
(a+b) * (c-d)
3.
(a+b/e) * (d+f).
Parenthesis
can be used in these expressions. Infix expression are the most natural way of
representing the expressions.
2. Postfix Expression :
In
this type of expressions the arrangement of operands and operator is as follows:
Postfix
expression = operand1 operand2 operator
For
example
1.
ab+
2.
ab + cd - *
3.
ab+e/df + *
In
postfix expression there is no parenthesis used. All the corresponding operands
come first and then operator can be placed.
3. Prefix Expression :
In
prefix expression the arrangement of operands and operators is as follows
Prefix
expression = operator operand1 operand2
For
example
1.
+ ab
2.
*+ ab - cd
3.
*/ +abe + df
In
prefix expression, there is no parenthesis used. All the corresponding operators
come first and then operands are arranged.
To
evaluate infix expression, we need the precedence and associativity of the
operators. And which is really a complex task. But in prefix and postfix
expressions corresponding operators are with their respective operands. But
these algorithms strongly recommend the use of stack.
Let
us now, discuss the conversion procedures of these expression.
C Programming and Data Structures: Unit III: b. Linear Data Structures Stacks and Queues : Tag: : three types: Infix, Postfix, Prefix | Stacks - Expression
C Programming and Data Structures
CS3353 3rd Semester EEE, ECE Dept | 2021 Regulation | 3rd Semester EEE Dept 2021 Regulation