I come from python and am trying to learn C, but I've only yesterday started with this pointer stuff. I wrote an inverted sorting algorithm that's supposed to take an unsorted array, then in each pass pick the highest and lowest elements, put them in each end then recursively do the same ignoring already sorted elements. The problem is I always get some error (different errors depending on what I try to change) which I can't fix regarding pointer types. Can you guys help?
#include <stdio.h>
void inv_cocksort(int *arr[], int first, int last);
int main(void)
{
int unsorted[11] = {3, 1, 4, 5, 4, 2, 6, 9, 2, 8, 7};
int unsorted_length = 11;
for (int i = 0; i < unsorted_length; i++)
{
printf("%i", unsorted[i]);
}
inv_cocksort(&unsorted, 0, unsorted_length-1);
for (int i = 0; i < unsorted_length; i++)
{
printf("%i", unsorted[i]);
}
void inv_cocksort(int *arr[], int first, int last)
{
if (first > last)
{
return;
}
else
{
for (int i = 0; i < last-1; i++)
{
if (arr[i] < arr[last])
{
int temp = *arr[last];
*arr[i] = *arr[last];
*arr[last] = temp;
}
if (arr[i] > arr[first])
{
int temp2 = *arr[first];
*arr[i] = *arr[first];
*arr[last] = temp2;
}
}
inv_cocksort(&arr[], first+1, last-1)
}
}
for (int i = 0; i < last-1; i++)tofor (int i = first; i < last-1; i++)or similar