### Trying to perform a swap to sort a vector

Hello,

I'm having issues with a swap function to sort a vector from highest value to lowest or vice versa.
Below is the code and with the current swap function it isn't doing anything when sorting and I don't know why.

The swap calls are in the quickSort function.

 1234567891011121314151617181920212223242526272829303132333435363738 template int partition(vector& set, int start, int end, bool (*compare)(const T&, const T&)) { int pivotIndex; int mid; T pivotValue; mid = (start + end) / 2; swap (set[start], set[mid]); pivotIndex = start; pivotValue = set[start]; for (int scan = start + 1; scan <= end; scan++) { if (compare(set[scan], pivotValue)) { pivotIndex++; swap (set[pivotIndex], set[scan]); } } swap(set[start], set[pivotIndex]); return pivotIndex; } template void swap(vector& a, vector& b) { vector temp = a; a = b; b = temp; }
Hello ritzbitz,

Welcome to the forum. and thank you for using code tags.

I am having problems setting up this code to compile and test. I do not know what you did in main before calling the "partition" function.

Looking at your code I am not sure right now if it will even work. Sorting a vector is much like sorting an array. Right now I am not sure if you are going about the sort the right way.

The "swap" function I do not believe that this is correct. You are defining "temp" as a whole vector when an int will do. Swapping the values of two elements is all you need to do.

The function name "partition" does not describe what the function does very well. I would stay away from a name like "sort" or "Sort" and maybe call it "SortVector" to describe what the function does.

If you do not mind posting the whole code so I can see what you did and better be able to test the code.

Andy