Skip to content

Instantly share code, notes, and snippets.

@danlark1
Created April 20, 2022 08:17
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/15d7db3acd6a64285bd7bc13a27f31a5 to your computer and use it in GitHub Desktop.
Save danlark1/15d7db3acd6a64285bd7bc13a27f31a5 to your computer and use it in GitHub Desktop.
// *__m is median. partition [__first, __m) < *__m and
// *__m <= [__m, __last)
//
// Special handling for almost sorted targets
while (true) {
while (__comp(*++__i, *__m));
while (!__comp(*--__j, *__m));
if (__i > __j) break;
swap(*__i, *__j);
}
swap(*__i, *__m);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment