Professional Documents
Culture Documents
To be filled by Student
Q.No.1 (Marks 2)
a. Write a program that will ask the user to input any number greater than 29.
b. Create a double linked list that will contain all the odd elements less than the number
which you entered in step (a). Also display this list.
c. Now ask the user to enter any pivot element. Pivot element is a simple integer number.
Use this pivot element to divide the list into two halves. First half will contain all the
elements smaller than that pivot element. Save this first half into a list called smallList.
Second half will contain all the elements larger than that pivot element. Save this second
half into a list called largeList.
d. In smallList, delete all the nodes at even position whereas in largeList, delete all nodes
at odd position.
Ans.
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
Question No. 2: [2 Marks]
Write a program that will take 10 integer values from the user.
a. If the entered value is Even then enqueue it into a queue at even index and if the entered
value is Odd then enqueue it into a queue at odd index. (Note: Even index will start from 0
& odd will start from 1 ).
b. Dequeue the values and display the sum of the even values and the sum of the odd values.
(Only write specific code, not system generated)
Answer:
_______
_________________________________________________________________________
In Several applications, more than one stack may be required together, some stacks overflow
whereas others are nearly empty, Suppose an application requires two stack X and Y ,One can
define an array A with Nx elements for stack X and another array B with Ny elements for stack
Y. Now instead of defining two separates arrays A and B, We can define a single array ,Say
AB ,with N=Nx+Ny elements for X and Y together ,Let us define the starting locations of items
for stack X and Y as AB[0] and AB[N] respectively and X grows to the right whereas Y grows
to the left
Using this scheme, we need the modified versions of push_A and pop_A as push_X ,push_Y
,pop_X and pop_Y .Similarly ,the operation STATUS_AB has to be defined to test the state of
empty or full, count of space occupied by X and Y, etc
0 1 2 N-2 N-1
N
1 2 3 5 7 8
X grows ----->> <<------Y
grows
Ans________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
Question No. 4 [6 Marks]
Alexa has two stacks of non-negative integers, stack A=[a0,a1,….,an-1] and stack
B=[b0,b1,..bm-1] where index denotes the top of the stack. Alexa challenges Nick to play
the following game:
• In each move, Nick can remove one integer from the top of either stack A or
stack B
• Nick keeps a running sum of the integers he removes from the two stacks.
• Nick is disqualified from the game if, at any point, his running sum becomes
greater than some integer given at the beginning of the game.
• Nick's final score is the total number of integers he has removed from the two
stacks.
Given A, B and x for games g, find the maximum possible score Nick can achieve
(i.e., the maximum number of integers he can remove without being disqualified)
during each game and print it on a new line.
The image below depicts the integers Nick should choose to remove from the stacks. We print
as our answer, because that is the maximum number of integers that can be removed from the
two stacks without the sum exceeding x=10.
Ans_______________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________