Dsa Mod1 Finals
Dsa Mod1 Finals
BSIT-NET2A
Intended Learning Activities
1.Convert the following expression to postsfix : 10 + 3 * 5 / ( 16 - 4)
Sr. no. Expression Stack Postfix
0 (
1 1 ( 1
2 0 ( 10
3 ( 10
4 + (+ 10
5 (+ 10
6 3 (+ 10 3
7 (+ 10 3
8 * (+* 10 3
9 (+* 10 3
10 5 (+* 10 3 5
11 (+* 10 3 5
12 / (+/ 10 3 5 *
13 (+/ 10 3 5 *
14 1 (+/( 10 3 5 * 1
15 6 (+/( 10 3 5 * 16
16 (+/( 10 3 5 * 16
17 - (+/(- 10 3 5 * 16
18 (+/(- 10 3 5 * 16
19 4 (+/(- 10 3 5 * 16 4
20 ) (+/ 10 3 5 * 16 4-
21 ) 10 3 5 * 16 4 - / +
2. Differentiate the 3 stack notations and by giving at least 3 examples in each notation.
1. Infix notation
- Infix notation is used to write expressions where operators are used in-between operands.
3. Postfix notation
- Postfix notation is used to write expressions operators are used in is written in afterwards operands.
class Test1 {
int val1 = stack.pop();
static int evaluatePostfix(String exp){ int val2 = stack.pop();
switch(c)
Stack<Integer> stack = new Stack<>();
{
while(Character.isDigit(c)) }
}
{ }
i++; }
c = exp.charAt(i);
public static void main(String[] args){
}
String exp = "100 200 + 2 / 5 * 7 +";
i --;
System.out.println(evaluatePostfix(exp));
stack.push(n); }
} }
else
{
Output:
757