本文整理汇总了C++中Comparator::on_less_rt方法的典型用法代码示例。如果您正苦于以下问题:C++ Comparator::on_less_rt方法的具体用法?C++ Comparator::on_less_rt怎么用?C++ Comparator::on_less_rt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Comparator
的用法示例。
在下文中一共展示了Comparator::on_less_rt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sort_template
void sort_template(xptr_sequence *xs, int off, int len)
{
Comparator comp;
// Insertion sort on smallest arrays
if (len < 7) {
for (int i=off; i<len+off; i++)
for (int j=i; j>off && comp.on_less(xs, j,j-1)<0; j--)
xs->swap(j, j-1);
return;
}
// Choose a partition element, v
int m = off + (len >> 1); // Small arrays, middle element
if (len > 7) {
int l = off;
int n = off + len - 1;
if (len > 40) { // Big arrays, pseudomedian of 9
int s = len/8;
l = comp.med3(xs, l, l+s, l+2*s);
m = comp.med3(xs, m-s, m, m+s);
n = comp.med3(xs, n-2*s, n-s, n);
}
m = comp.med3(xs, l, m, n); // Mid-size, med of 3
}
xptr v = xs->get(m);
// Establish Invariant: v* (<v)* (>v)* v*
int a = off, b = a, c = off + len - 1, d = c;
while(true) {
while (b <= c && comp.on_less_lt(xs, b, v)<=0) {
if (xs->get(b) == v)
xs->swap(a++, b);
b++;
}
while (c >= b && comp.on_less_rt(xs,v,c)<=0) {
if (xs->get(c) == v)
xs->swap(c, d--);
c--;
}
if (b > c)
break;
xs->swap(b++, c--);
}
// Swap partition elements back to middle
int s, n = off + len;
s = s_min(a-off, b-a ); xs->vecswap( off, b-s, s);
s = s_min(d-c, n-d-1); xs->vecswap( b, n-s, s);
// Recursively sort non-partition-elements
if ((s = b-a) > 1)
sort_template<Comparator>(xs, off, s);
if ((s = d-c) > 1)
sort_template<Comparator>(xs, n-s, s);
}