Aryaman Sharma Worksheet 8 and 9 (20bcs4206)
Aryaman Sharma Worksheet 8 and 9 (20bcs4206)
Aryaman Sharma Worksheet 8 and 9 (20bcs4206)
Institutional Training
June-July, 2021
Department of AIT-CSE
Daily Worksheet - Day-8 and 9
STACK DATA STRUCTURES
**************************************************************
void fun(int n)
{
Stack S; // Say it creates an empty stack S
while (n > 0)
{
// This line pushes the value of n%2 to stack S
push(&S, n%2);
n = n/2;
}
// Run while Stack S is not empty
while (!isEmpty(&S))
printf("%d ", pop(&S)); // pop an element from S and print it
}
Department of AIT-CSE
**************************************************************
Question 2: Assume that the operators +, -, × are left associative and ^ is right
associative. The order of precedence (from highest to lowest) is ^, x , +, -. The
postfix expression corresponding to the infix expression a + b × c - d ^ e ^ f is
**************************************************************
Question 3: Pankaj and Mythili were both asked to write the code to evaluate the
following expression:
a - b+ c/(a-b) + (a-b)^2
d = (a-b)
Department of AIT-CSE
Answer: The correct option is A i.e. Code A uses lesser memory and is slower than
Code B.
Code A uses less memory as it has only 3 variables whereas in Code B there are 4
variables and Code A is slower because compiler has to calculate ( a – b ) every
time whereas in Code B ( a – b ) value is stored in another variable, so compiler
does not have to calculate every time.
**************************************************************
b = a/d
c=a-b
print c
a) 410
Department of AIT-CSE
b) 410.4
c) 411.4
d) 411
**************************************************************
Answer:
Department of AIT-CSE
**************************************************************
Answer:
Department of AIT-CSE
**************************************************************