Another approach insertion sort

please review my code i done with other approach please see its valid or not…

https://ide.codingblocks.com/s/188685

thanks in advance

@Diwyanshu There was a slight error in your code ,instead of i you need to deal with j in your inner loop. Also you can add a break statement in the loop as well to optimise it.

for (int j = i; j >=0 ; --j)
{
  
  if(a[j] > a[j+1])
  {
    temp = a[j];
    a[j] = a[j+1];
    a[j+1] = temp;
  }
  else break;
         
}

This is how your inner loop now looks like.

is my approach ok because in video its done in other way @KeshavGupta

Your code was giving wrong answer , so you needed to make the changes that I suggested to make it work.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.