Fill in the blanks for completing the program to rotate an array by d elements.
C++
/*Function to left rotate arr[] of size n by d*/ void Rotate( int arr[], int d, int n)
{ int p = 1;
while (_______) {
int last = arr[0];
for ( int i = 0; ______ i++) {
arr[i] = arr[i + 1];
}
__________
p++;
}
} |
(A)
p <= d , i < n – 1 , arr[n – 1] = last;
(B)
p < d, i < n, arr[n] = last;
(C)
p >=d, i >n , arr[n] = last
(D)
None
Answer: (A)
Explanation:
In the three blanks given in the questions.
- The first blank will be a conditional statement which should be (p.<=d) because p starts with 1 and goes till d.
- The second blank should be the condition for looping, which is (i < n-1), because the loop will run till n-1 elements.
- and the last blank will be updating the last element.
Hence Option(A) is correct.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Article Tags :
Uncategorized
Recommended Articles