Page 42 - C++
P. 42

(1 mark for applying condition to check if Queue is empty)
                      (½ mark for returning -1)
                      (1 mark for deleting the first element from the Queue)
                      (½ mark for returning the deleted value)
               d)     Write a generator function to generate odd numbers between a and b (including b).Note:       3
                      a and b are received as an argument by the function.
               Ans:





                      (½ mark for correct function header)

                      (1 mark for correct use of loop)
                      ( ½ mark for condition)
                      (1 mark for using yield() to yield the correct value)
               (e)    Evaluate the following postfix expression using a stack. Show the contents of stack after    2
                      execution of each operation:
                      10,40,25,-,*,15,4,*,+
               Ans
                        Symbol  Operation                Stack       Result

                        10        Push(10)               10

                        40        Push(40)               10,40

                        25        Push(25)               10,40,25

                        -         Pop(25)                10,15
                                  Pop(40)
                                  Push(40-25)
                                  =15

                        *         Pop(15)                150
                                  Pop(10)
                                  Push(10*15)
                                  =150


                        15        Push(15)               150,15

                        4         Push(4)                150,15,4

                        *         Pop(4)                 150,60
                                  Pop(15)
                                  Push(15*4)=60


                                                        Page No. 25
   37   38   39   40   41   42   43   44   45   46   47