order_statistic.h
Go to the documentation of this file.
1 
2 #ifndef _ORDER_STATISTIC_H
3 #define _ORDER_STATISTIC_H
4 
5 #include <alglib/sort/sort.h>
6 
7 namespace alglib {
8 namespace order_stat {
9 
10 
11 template<typename RandomAccessIter>
12 RandomAccessIter select_i(RandomAccessIter _first, RandomAccessIter _last, int i) {
13 
14  if(_last <= _first)
15  return _last;
16 
17  RandomAccessIter pivot = randomized_partition(_first, _last);
18  int k = pivot - _first + 1;
19 
20  if(k == i)
21  return pivot;
22 
23  else if(i < k)
24  return select_i(_first, pivot, i);
25 
26  else
27  return select_i(pivot + 1, _last, i - k);
28 }
29 
30 } // end of order_stat namespace
31 } // end of alglib namespace
32 
33 #endif
Definition: bimap.h:17
RandomAccessIter randomized_partition(RandomAccessIter first, RandomAccessIter last, const BinaryPred &LT)
Definition: sort.h:82
RandomAccessIter select_i(RandomAccessIter _first, RandomAccessIter _last, int i)
Definition: order_statistic.h:12