Untitled

mail@pastecode.io avatar
unknown
csharp
3 years ago
557 B
2
Indexable
Never
static void insertionSort(int[] v, int n)
        {
            for (int l = 1; l < n; l++)
            {
                int j = l; //Smallest (left) 
                int i = l; //Counter
                while (i > 0 && v[l] < v[i - 1])
                {
                    j = i - 1;
                    i--;
                }

                int temp = v[l];
                for (int x = l; x >= j + 1; x--)
                {
                    v[x] = v[x - 1];
                }
                v[j] = temp;
            }
        }