Sort algorithm and an ugly error
There's my sort algorithm. Please don't tell me whether its a good one or not, I'm trying out some ideas and need to find out for myself.
// Bubble sort function. Sorts an array of ints in descending order.
void pointerBubbleSort(apvector <element> &array, int n)
apvector <element*> pointer(n);
int i, j, flag = 1;
for (i = 0; i < n; i++)
pointer[i] = &array[i];
for(i = 1; (i <= n) && flag; i++)
flag = 0;
for(j = 0; j < (n - i); j++)
if (pointer[j + 1] > pointer[j])
temp = pointer[j + 1];
pointer[j + 1] = pointer[j];
pointer[j] = temp;
flag = 1;
I'm trying to sort using pointers to characters in a vector. For some reason it is always going out of bounds with a negative number, even if I initialize them to death. Apvector has bounds checking, and it keeps closing the program.