Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@danlark1
Last active June 19, 2022 18:14
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/59d0726f6624c08202ff2653b3563b0a to your computer and use it in GitHub Desktop.
Save danlark1/59d0726f6624c08202ff2653b3563b0a to your computer and use it in GitHub Desktop.
// Use Tuckey's ninther technique or median of 3 for pivot selection.
// Get the median out of 3 medians of 9 elements
// (first, first + half, last - 1)
// (first + 1, first + half - 1, last - 2)
// (first + 2, first + half + 1, last - 3)
_VSTD::__sort3<_Compare>(__first,
__first + __half_len,
__last - difference_type(1),
__comp);
_VSTD::__sort3<_Compare>(__first + difference_type(1),
__first + (__half_len - 1),
__last - difference_type(2),
__comp);
_VSTD::__sort3<_Compare>(__first + difference_type(2),
__first + (__half_len + 1),
__last - difference_type(3),
__comp);
_VSTD::__sort3<_Compare>(__first + (__half_len - 1),
__first + __half_len,
__first + (__half_len + 1),
__comp);
_VSTD::iter_swap(__first, __first + __half_len);
@drudru
Copy link

drudru commented Jun 19, 2022

Mispelling: It is "Tukey's" ninther not "Tuckey's"

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