I want to make some basics clear
Now In insertion sort we use 2 for loops and inside the for loop we keep track of key element which is to be inserted
CODE
for(int i = 0 ; i < n ; i++)
` `int key = a[i]
int j = i-1
while j >= 0 && a[i] < a[j]:
a[j+1] = a[j]
j--
a[j+1] = a[i]
What difference it will make when we write code like this(predefining variables)
int i,key,j;
for(i = 0 ; i < n ; i++)
` `key = a[i]
j = i-1
while j >= 0 && a[i] < a[j]:
a[j+1] = a[j]
j--
a[j+1] = a[i]