I've got a task to code some sorting function by passing pointers. Unfortunately, pointers are just one of those concepts my brain doesn't seem to comprehend.
Here's the call:
int size = 10000;
int* data = new int[size];
//omitted code that populates array for the sake of space
selectionSort(data, data+size);
And here's my incorrect attempt at the function:
void selectionSort(int* first, int* last) {
for (int* i = first; i < last-1; i++) {
int* min = i;
for (int* j = i+1; j < last; j++) {
if (j < min) {
min = j;
}
int* temp = i;
i = min;
min = temp;
}
}
}
Basically, I'm having trouble figuring out what happens when I'm comparing one pointer with another, or adjusting a pointer. Is it adjusting/comparing the value it's pointing too or is it comparing the actual pointers themselves?
Any help is appreciated. Cheers.
*min = *j. Also you wanti < lastsincelastis one position pass the last element -- usual convention followed by stl.