P.D.E.
A’s
Prof. Ramkrishna More Arts, Commerce and Science College,
Akurdi, Pune-44
S.Y.B.Sc.(Comp.Sci.) 2022-23
Subject: (CS-231) : Data Structures and Algorithms – I
Assignment-3
Chapter 4 : Stack
Q.1] Attempt the following : [1 Marks]
1. Name the data structure used in recursion.
2. Write any two applications of stack.
3. Convert the following infix expression to postfix form
a) ( A * B * C) / ( ( F * C ) – D)
b) P – Q^R + S * T - U
Q.2] Attempt the following : [4 or 3 Marks]
1. Give the output of the following code 2. Give the output of the following
segment : code :
void fun (int n) { int i = 1, x, y, z ;
{ initstack ( ) ;
struct stack s ; while ( i < 5)
initstack(&s); {
while (n > 0) push (i * 2) ; i = i + 1;
{ }
push (&s, n%2); x = pop ( ) ;
n = n/2; y = pop ( ) ;
} Push ( i*i ) ;
while (! isempty (&s)) z = POP ( ) ;
printf (“%d”, pop (&s)); push (x + y) ;
} push (x + z) ;
The call to the function is fun (10), also while (! stackempty ( ) )
explain the steps of the output. printf (“\n %d”, pop ( ) ) ;
}
Also explain the steps of the output.
3. Consider the given infix expression u * v + z/w. Write its postfix expression. Also show
steps to evaluate the postfix expression using stack.
Given : u = 3, v = 1, z = 4, w = 2.
4. Write a ‘C’ function to reverse a string using stack (Do not define any stack functions).
5. Write a ‘C’ function to check if a string is a palindrome using stack. (Do not write stack
functions).
Mr. S. G. Lakhdive
P.D.E.A’s
Prof. Ramkrishna More Arts, Commerce and Science College,
Akurdi, Pune-44
S.Y.B.Sc.(Comp.Sci.) 2022-23
Subject: (CS-231) : Data Structures and Algorithms – I
Assignment-3
Chapter 4 : Stack