Solution in C#-
class Solution {
static void insertionSort1(int n, int[] arr) {
int x = arr[n-1];
int i;
for(i=n-2; i>=0; i--)
{
if(arr[i]>x)
{
arr[i+1] = arr[i];
Console.WriteLine(string.Join(" ",arr));
}
else
{
arr[i+1] = x;
break;
}
}
if(i==-1)
arr[0] = x;
Console.WriteLine(string.Join(" ",arr));
}
static void Main(string[] args) {
int n = Convert.ToInt32(Console.ReadLine());
int[] arr = Array.ConvertAll(Console.ReadLine().Split(' '), arrTemp => Convert.ToInt32(arrTemp));
insertionSort1(n, arr);
}
}
Post a Comment