I am trying to use a pointer for an array for selection sort.
void sort(int size, int *ptr)
{
int temp;
bool swap;
do
{
swap = false;
for (int count = 0; count < (size - 1); count++)
{
if (*ptr[count] > *ptr[count + 1])
{
temp = *ptr[count];
*ptr[count] = *ptr[count + 1];
*ptr[count + 1] = temp;
swap = true;
}
}
} while (swap);
}
im getting a lot of errors saying illegal direction because when using * it must be a pointer. I use it in other methods fine its just this one that it has trouble. This is the call im using.
sort(arraySize, numArray);
everything is declared and working in other methods.
ptr[count]and not*ptr[count]. ptr is a pointer and not an array of pointers.*ptr[count]to justptr[count]. You do not need to dereference a pointer if you are using array subscript. Pointers can be dereferenced with either the * operator or with an array subscript in most cases.