Is my implementation of insertion sort is correct? I'm currently learning about different sorting algorithms and after reading on the concept of the insertion sort of how it's done I've tried to implement it by myself before seeing how it was implemented in the source from which I'm learning.

This was my implementation:

void insertionSort(int arr[])
{
    for(int i = 1; i &lt; SIZE; i++)
    {
        int j = i;
        while(j &gt; 0 &amp;&amp; arr[j] &lt; arr[j - 1])
        {
            int swap = arr[j];
            arr[j] = arr[j + 1];
            arr[j + 1] = swap;
            j--;
        }
    }
}


Now I think I've implemented it correctly (not talking about efficient or anything just the algorithm itself), but when I saw the way it was implemented in the course I'm seeing I had a bit of concerns about my implementation because they're really different and I just wanted to make sure my implementation is really an insertion sort algorithm implementation and I didn't done anything else.

Here's the implementation by the source I'm learning from:


void insertionSort(int arr[])
{
  for(int i = 1;, i &lt; SIZE; i++)
  {
      int value = arr[i];
      int j = i - 1;
      int done = 0;
      do
      {
          if (arr[j] &gt; value)
          {
              arr[j + 1] = arr[j];
              j--;
              if (j &lt; 0)
                  done = 1;
          }
          else
          {
              done = 1;
          }
      } while(!done)
      arr[j + 1] = value;
  }
}



Also I would appreciate if you could compare my implementation to the one made by the source I'm learning from, any efficient differences or any other thing you think would worth mentioning.
By inspection, your implementation is incorrect: arr[0] can never be written to.  The only code that writes to arr is inside the while loop, and the body of the while loop will only execute when j &gt; 0.

In addition, the style could be improved.  Any code of the form

int j = …;
while (some condition involving j)
{
    …
    j--;
}


would be more easily recognizable if written as a for-loop.

The body of the inner loop looks like it performs swaps with neighbouring elements.  You should be able to shift multiple elements over by one slot by doing fewer writes than that.