‹ Back to the paper
The following program code sorts a single dimensional array in ascending order using Insertion Sort…
The following program code sorts a single dimensional array in ascending order using Insertion Sort technique. There are some places in the code marked as ?1?, ?2?, ?3?, ?4? and ?5? which are to be replaced by a statement/expression so that the code works properly.
void insertionSort(int array[])
{
int n = ?1?;
for (int j = 1; j < n; j++)
{
int key = ?2?;
int i = j - 1;
while ((i > -1) && (array[i] > ?3?))
{
array[i + 1] = ?4?;
i--;
}
?5? = key;
}
}
What is the statement or expression at ?4?- (i)j+1
- (ii)key
- (iii)array[j]
- (iv)array[i]
Answer
No answer yet.
From ISC 2022 Computer Science - Specimen paper (Semester 1), Paper 1, question 32(d).