mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
use median of three to increase our chances
This commit is contained in:
parent
b0c9bc7d41
commit
7d6418220e
1 changed files with 12 additions and 2 deletions
|
|
@ -18,11 +18,21 @@ static inline void swap(TYPE *a, int i, int j)
|
|||
a[j] = t;
|
||||
}
|
||||
|
||||
template <typename TYPE>
|
||||
static inline void sort(TYPE *a, int i, int j, int k)
|
||||
{
|
||||
if (a[i] > a[j])
|
||||
swap(a, i, j);
|
||||
if (a[i] > a[k])
|
||||
swap(a, i, k);
|
||||
if (a[j] > a[k])
|
||||
swap(a, j, k);
|
||||
}
|
||||
|
||||
template <typename TYPE>
|
||||
static int partition(TYPE *a, int l, int h)
|
||||
{
|
||||
int p = (l + h) / 2;
|
||||
swap(a, p, h);
|
||||
sort(a, (l + h) / 2, h, l);
|
||||
for (int i = l; i < h; ++i)
|
||||
if (a[i] < a[h])
|
||||
swap(a, i, l++);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue