Skip to content

Instantly share code, notes, and snippets.

@danlark1
Created April 12, 2022 19:30
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 danlark1/cbce7cece7975987efc7450e3e2a68b5 to your computer and use it in GitHub Desktop.
Save danlark1/cbce7cece7975987efc7450e3e2a68b5 to your computer and use it in GitHub Desktop.
sort4
template <class _Compare, class _ForwardIterator>
unsigned __sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3, _ForwardIterator __x4,
_Compare __c) {
unsigned __r = _VSTD::__sort3<_Compare>(__x1, __x2, __x3, __c);
if (__c(*__x4, *__x3)) {
swap(*__x3, *__x4);
++__r;
if (__c(*__x3, *__x2)) {
swap(*__x2, *__x3);
++__r;
if (__c(*__x2, *__x1)) {
swap(*__x1, *__x2);
++__r;
}
}
}
return __r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment