- The smallest element is at index $1$,$1$.
- So we have to give an array which is partially sorted. Definition of partially sorted is given in the question.
We will give the value of $x$ which is less than last row & column value.
At last, $1$,$1$ should be deleted & $x$ should be at its correct place.
i=1;j=1; a[i][j]=x;
while ((x>a[i+1][j]) || (x>a[i][j+1]))
{
if((a[i+1][j] < x) && (a[i+1][j] <a[i][j+1]))
{
a[i][j]=a[i+1][j];
i=i+1;
}
else
{
a[i][j]=a[i][j+1];
j=j+1;
}
}
a[i][j]=x;
Enter the dimension of $n\times n$ array. Give the value of $n$
$3$
Enter the array elements in partially sorted order
$2$ $3$ $9$
$5$ $6$ $10$
$8$ $11$ $15$
Enter the value of $x$
$7$
The final output.
$3$ $6$ $9$
$5$ $7$ $10$
$8$ $11$ $15$