mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
use l and h to specify ranges to work on
This commit is contained in:
parent
f83ca91608
commit
c0adfaef64
1 changed files with 7 additions and 9 deletions
16
quick.hh
16
quick.hh
|
|
@ -58,11 +58,11 @@ static void partition(TYPE *a, int &l, int &h)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename TYPE>
|
template <typename TYPE>
|
||||||
static void insertion(TYPE *a, int n)
|
static void insertion(TYPE *a, int l, int h)
|
||||||
{
|
{
|
||||||
for (int i = 1, j; i < n; ++i) {
|
for (int i = l + 1, j; i <= h; ++i) {
|
||||||
TYPE t = a[i];
|
TYPE t = a[i];
|
||||||
for (j = i; j > 0 && t < a[j-1]; --j)
|
for (j = i; j > l && t < a[j-1]; --j)
|
||||||
a[j] = a[j-1];
|
a[j] = a[j-1];
|
||||||
a[j] = t;
|
a[j] = t;
|
||||||
}
|
}
|
||||||
|
|
@ -72,9 +72,8 @@ template <typename TYPE>
|
||||||
static void sort(TYPE *a, int l, int h)
|
static void sort(TYPE *a, int l, int h)
|
||||||
{
|
{
|
||||||
if (l < h) {
|
if (l < h) {
|
||||||
int n = h - l + 1;
|
if (h - l < 32) {
|
||||||
if (n <= 32) {
|
insertion(a, l, h);
|
||||||
insertion(a+l, n);
|
|
||||||
} else {
|
} else {
|
||||||
int lt = l, gt = h;
|
int lt = l, gt = h;
|
||||||
partition(a, lt, gt);
|
partition(a, lt, gt);
|
||||||
|
|
@ -88,9 +87,8 @@ template <typename TYPE>
|
||||||
static void select(TYPE *a, int l, int h, int k)
|
static void select(TYPE *a, int l, int h, int k)
|
||||||
{
|
{
|
||||||
while (l < h) {
|
while (l < h) {
|
||||||
int n = h - l + 1;
|
if (h - l < 32) {
|
||||||
if (n <= 32) {
|
insertion(a, l, h);
|
||||||
insertion(a+l, n);
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
int lt = l, gt = h;
|
int lt = l, gt = h;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue