Generic insertion sort in C
<p>I have coded a generic insertion sort in C, and it works really fine. </p>

<p>But, On my function of insertion sort, it gets a <code>void** arr</code>,
and on its signature it gets a <code>void* arr</code>, otherwise, it doesn't work.</p>

<p>Why is it so?
Do we have any other ways to code the insertion sort to be generic?</p>

<p>The Full code is here:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;malloc.h&gt;
#define SIZE 10
int cmp(void* elm1, void* elm2);
void insertionSort(void* arr, int size);

int main()
{
    int arr[] = {5, 8, 2, 3, 15, 7, 4, 9, 20, 13};
    int arr2[] =  {1};
    int i;
    for (i = 0; i &lt; SIZE; i++)
        printf("%d ", arr[i]);
    printf("\n");
    insertionSort(&amp;arr, SIZE);
    for (i = 0; i &lt; SIZE; i++)
        printf("%d ", arr[i]);
    return 0;
}

void insertionSort(void** arr, int size)
{
    int i = 1;
    int j;
    void* temp;
    while (i &lt; size)
    {
        if (cmp(arr[i], arr[i-1]) == -1)
        {
            temp = arr[i];
            j = i - 1;
            while (j &gt;= 0 &amp;&amp; cmp(arr[j], temp) == 1)
            {
                arr[j + 1] = arr[j];
                j--;
            }
            arr[j + 1] = temp;
        }
        i++;
    }
}

int cmp(void* elm1, void* elm2)
{
    if ((int)elm1 == (int)elm2)
        return 0;
    else if ((int)elm1 &gt; (int)elm2)
        return 1;
    else 
        return -1;
}
</code></pre>