HackerRank - Insertion Sort - Part 2
Probably the single biggest (or most obvious, anyway) improvement would be to write an actual insertion sort. What you have right now appears to be a bubble sort rather than an insertion sort.

Rather than swapping elements that are out of order an insertion sort divides the array into a sorted part and an unsorted part. In the beginning, the sorted part is just the first element. Then it looks at the first element of the unsorted part, copies it into a temporary location, and copies elements in the sorted part "forward" a spot until it gets to an element smaller than the temporary. That makes a "hole" for the new element to go into, and it puts that element there (then repeats for the remaining unsorted elements).

Given an array v of n elements, the loops look something like this:

for (int i=1; i&lt;n; i++) {
    tmp = v[i];
    int j;
    for (j=i; j&gt;0 &amp;&amp; tmp&lt;v[j-1]; j--)
        v[j] = v[j-1];
    v[j] = tmp;
}