Page 41 - C++
P. 41
Q3 (a) Write the definition of a function Reverse(X) in Python, to display the elements in 2
reverse order such that each displayed element is the twice of the original element
(element * 2) of the List X in the following manner:
Example:
If List X contains 7 integers is as follows:
X[0] X[1] X[2] X[3] X[4] X[5] X[6]
4 8 7 5 6 2 10
After executing the function, the array content should be displayed as follows:
20 4 12 10 14 16 8
Ans
(1 mark for correct loop)
(1 mark for displaying twice of the list element)
(b) Consider the following unsorted list : 3
[22, 54, 12, 90, 55, 78]
rd
Write the passes of selection sort for sorting the list in ascending order till the 3
iteration.
Ans Pass 1: [12, 54, 22, 90, 55, 78]
Pass 2 : [12, 22, 54, 90, 55, 78]
Pass 3 : [12, 22, 54, 90, 55, 78]
(1 mark to produce correct List after each pass.)
(c) Consider the following class Order and do as directed: 4
Blank 1
:
:
i. Fill in the blank 1 with a statement to insert OID in the Queue maintained using List
L.
ii. Complete the definition of delorder() to delete OID from the Queue maintained using
List L, the function should return the OID being deleted or -1 in case the Queue is
empty.
Ans: i. self.L.append(self.OID)
( 1 mark for the correct answer)
ii.
Page No. 24