Professional Documents
Culture Documents
Course Objective
o Implement various data structures and their algorithms, and apply them in implementing simple applications.
o Analyze simple algorithms and determine their complexities.
o Apply the knowledge of data structures to other application domains.
o Design new data structures and algorithms to solve problems
Class Policy
1. A student must reach the class-room in time. Students late than 8 mins may join the class but are not entitled to be marked
present.
2. Attendance shall be marked at the start of the class and students failing to secure 75% attendance will not be allowed to sit
in the Final Exam.
3. Those who are absent on the announcement date of the assignment/test, must get the topic/chapter of the test/assignment
confirmed through their peers
Order of Operators:
Infix to Postfix
Solution:
o (A+B)*C/D
AB + * C/D, suppose AB+ = p
P * C/D
PC* /D , suppose (PC* = q)
Q / D;
QD/
PC* D (putting values )
AB+C*D/ (putting values)
Step No.1:
Convert the current expression into reverse order.
C+ (B*A)
Step No.2:
Infix to postfix conversion
Symbol Stack Postfix
C - C
+ + C
( +( C
B +( CB
* +(* CB
A +(* CBA
) + CBA*
CBA*+
Step No.3:
Revers the postfix expression, that will be the final answer and prefix expression.
+*ABC
As Postfix expression is without parenthesis and can be evaluated as two operands and an operator
at a time, this becomes easier for the compiler and the computer to handle.
o While reading the expression from left to right, push the element in the stack if it is an
operand.
o Pop the two operands from the stack, if the element is an operator and then evaluate it.
o Push back the result of the evaluation. Repeat it till the end of the expression.
o Expression: 456*+
Postfix Evaluation C++ Program
#include<iostream>
#include<cmath>
#include<stack>
int value;
value = ch;
//Perform operation
if(op == '+')
return b+a;
return b-a;
return b*a;
else
int a, b;
stack<float> stk;
string::iterator it;
if(isOperator(*it) != -1) {
a = stk.top();
stk.pop();
b = stk.top();
stk.pop();
stk.push(operation(a, b, *it));
stk.push(scanNum(*it));
return stk.top();
main() {