Skip to content

Instantly share code, notes, and snippets.

@joonas-yoon
Created March 19, 2020 08:07
Show Gist options
  • Save joonas-yoon/f4fad0c8b1e4aa19e3e99431e3731681 to your computer and use it in GitHub Desktop.
Save joonas-yoon/f4fad0c8b1e4aa19e3e99431e3731681 to your computer and use it in GitHub Desktop.
alternative for STL - sort(quick)
// based on quick sort
template<typename T>
void sort(T *arr, T *end) {
int l = 0, r = (end - arr) - 1;
if (l >= r) return;
T mid = arr[(l + r) / 2];
while (l <= r) {
while (arr[l] < mid) ++l;
while (mid < arr[r]) --r;
if (l <= r) {
swap(arr[l++], arr[r--]);
}
}
sort(arr, arr + l);
sort(arr + l, end);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment