Skip to content

Instantly share code, notes, and snippets.

@ercanozkaya
Created December 17, 2015 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ercanozkaya/0bf58a976d3ab27c48ff to your computer and use it in GitHub Desktop.
Save ercanozkaya/0bf58a976d3ab27c48ff to your computer and use it in GitHub Desktop.
sort.cpp
template<class Iterator>
void quickSort(Iterator begin, Iterator end)
{
Iterator pivot = begin;
if (begin == end) {
return;
}
int i = 1,
size = end - begin;
// Convert the iterator into (pivot,<pivot,>pivot) format
for (int j = 1; j < size; j++) {
if (*(begin+j) < *pivot) {
swap(*(begin+j), *(begin+i));
i++;
}
}
// Put pivot in the middle
swap(*pivot, *(begin+i-1));
// Sort the <pivot and >pivot partitions
quickSort(begin, begin+i-1);
quickSort(begin+i,end);
}
@ercanozkaya
Copy link
Author

vector user2score;
quickSort<vector::iterator>(user2score.begin(), user2score.end());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment